-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.pde
More file actions
64 lines (56 loc) · 1.29 KB
/
Particle.pde
File metadata and controls
64 lines (56 loc) · 1.29 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
class Particle {
public Emitter emitter;
public float x = 0.0;
public float y = 0.0;
public float z = 0.0;
public float friction = 0.98; // 0-1 0=immovable, 1=no friction
public float scale = 1.0;
public int age = 0;
public boolean dead = true;
public Force inertia = new Force();
public ArrayList<Force> forces = new ArrayList<Force>();
public ParticleSettings settings;
PShape shape;
Particle(){
}
private void setupShape(){
shape = createShape(RECT, -5, -5, 10, 10);
shape.setFill(settings.fillColor);
shape.setStroke(false);
}
public void setup(Emitter e){
x = e.x;
y = e.y;
z = e.z;
emitter = e;
age = 0;
dead = false;
settings = e.particleSettings;
setupShape();
inertia = e.inertia.clone();
forces = new ArrayList<Force>();
}
public void move(){
//update inertia
inertia.speed *= friction;
inertia.applyTo(this);
//for each force move particle
for (Force f : forces){
f.applyTo(this);
}
checkForDead();
}
public void draw(){
shape(shape, x, y);
}
public void checkForDead(){
if (++age >= settings.lifespan){
dead = true;
return;
}
if (x < 0 || y < 0 || x > width || y > width){
dead = true;
return;
}
}
}