-
Notifications
You must be signed in to change notification settings - Fork 0
/
Particle.pde
44 lines (35 loc) · 918 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
class Particle {
PVector loc, vel, acc;
float maxSpeed, mass;
Particle() {
loc = new PVector(random(width), random(height));
vel = new PVector(5, -10);
acc = new PVector(0, 0.1);
maxSpeed = 5;
mass = 2;
}
void applyForce(PVector force_) {
acc.add(force_);
}
void follow(perlinNewtonFlowfield ff){
PVector desired = new PVector(cos(ff.lookup(loc)), sin(ff.lookup(loc)));
desired.mult(maxSpeed);
PVector steer = PVector.sub(desired,vel);
steer.limit(maxSpeed);
applyForce(steer);
}
void update() {
vel.limit(maxSpeed);
vel.add(acc);
loc.add(vel);
acc.mult(0);
}
void show() {
ellipse(loc.x, loc.y, mass, mass);
}
void checkEdges(){
if(loc.x > width || loc.x < 0 || loc.y > height || loc.y < 0){
loc = new PVector(random(width), random(height));
}
}
}