aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deprecated/ZJW/javascripts/viz.pde')
-rw-r--r--deprecated/ZJW/javascripts/viz.pde81
1 files changed, 81 insertions, 0 deletions
diff --git a/deprecated/ZJW/javascripts/viz.pde b/deprecated/ZJW/javascripts/viz.pde
new file mode 100644
index 0000000..4084708
--- /dev/null
+++ b/deprecated/ZJW/javascripts/viz.pde
@@ -0,0 +1,81 @@
1ArrayList particles;
2int maxParticles = 255;
3
4void setup() {
5 size(window.innerWidth, window.innerHeight);
6 particles = new ArrayList();
7 rectMode(CENTER);
8}
9
10void draw() {
11 background(21, 32, 46);
12
13 if(particles.size() < maxParticles) {
14 x = random(0, width);
15 y = random(0, height);
16 PVector l = new PVector(x, y);
17 Particle particle = new Particle(l);
18 particles.add(particle);
19 }
20
21
22 for(int i=0; i<particles.size(); i++) {
23 Particle p = (Particle) particles.get(i);
24 Particle next;
25
26 if(i>1) {
27 next = (Particle) particles.get(i-1);
28 stroke(57,219,255,10);
29 line(next.location.x, next.location.x, p.location.x, p.location.y)
30 }
31
32
33 // Run the particle
34 p.run();
35
36 if(p.isDead()) {
37 particles.remove(i);
38 }
39 }
40}
41
42class Particle {
43 PVector location;
44 PVector velocity;
45 PVector acceleration;
46 float lifespan;
47 float rectSize;
48
49 Particle(PVector l) {
50 location = l.get();
51 velocity = new PVector(random(0,0.05),random(0.02, 0.8));
52 acceleration = new PVector(random(0, 0.01),random(0,0.01));
53 lifespan = 255.0;
54 rectSize = 5;
55 }
56
57 void run() {
58 display();
59 update();
60 }
61
62 void display() {
63 noStroke();
64 fill(73, 219, 255, lifespan/5);
65 rect(location.x, location.y, rectSize, rectSize);
66 }
67
68 void update() {
69 lifespan -= 2;
70 velocity.add(acceleration);
71 location.add(velocity);
72 }
73
74 boolean isDead() {
75 if (lifespan < 0) {
76 return true;
77 } else {
78 return false;
79 }
80 }
81}
Powered by cgit v1.2.3 (git 2.41.0)