-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.pde
52 lines (47 loc) · 875 Bytes
/
Particle.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Particle
{
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
color col;
Particle(PVector l)
{
acceleration = new PVector(0,0.05);
float theta = random(0,360);
velocity = new PVector(cos(radians(theta))*random(4,5),sin(radians(theta))*random(4,5));
location = l.get();
lifespan = 255.0;
col = #66FF00;
}
void run()
{
update();
display();
}
// method to update location
void update()
{
velocity.add(acceleration);
location.add(velocity);
lifespan -= 2.0;
}
// method to display
void display()
{
stroke(#981414,lifespan);
fill(col, lifespan);
ellipse(location.x,location.y, 4, 4);
}
// is the particle still useful?
boolean isDead()
{
if (lifespan < 0.0)
{
return true;
} else
{
return false;
}
}
}