-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.pde
More file actions
46 lines (39 loc) · 900 Bytes
/
Particle.pde
File metadata and controls
46 lines (39 loc) · 900 Bytes
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
//daniel shiffman's code
public class Particle {
protected PVector position;
private PVector velocity;
private PVector acceleration;
protected float lifespan;
final static protected float r = 6;
Particle(float x, float y) {
acceleration = new PVector();
velocity = PVector.random2D();
position = new PVector(x, y);
lifespan = 255.0;
}
void applyForce(PVector f) {
acceleration.add(f);
}
// Method to update position
void update() {
velocity.add(acceleration);
position.add(velocity);
acceleration.mult(0);
lifespan -= 1;
}
// Method to display
void display() {
stroke(0, lifespan);
strokeWeight(2);
fill(127, lifespan);
ellipse(position.x, position.y, r*2, r*2);
}
// Is the particle still useful?
boolean isDead() {
if (lifespan < 0.0) {
return true;
} else {
return false;
}
}
}