-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.pde
73 lines (64 loc) · 1.28 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Particle{
PVector pos;
PVector vel;
PVector acc;
PVector force;
PVector[] vArr;
int normPosX;
int normPosY;
int res;
int index;
int rowsize;
int colsize;
int maxspeed = 2;
Particle(int rows, int cols, int scl, PVector[] vectorArr){
pos = new PVector(random(width),random(height));
//vel = PVector.random2D();
vel = new PVector(0,0);
acc = new PVector(0,0);
res = scl;
rowsize = rows;
colsize = cols;
vArr = new PVector[rows*cols];
vArr = vectorArr;
//update();
}
void update(){
vel.add(acc);
vel.limit(maxspeed);
pos.add(vel);
acc.mult(0);
}
void applyForce(PVector force){
acc.add(force);
}
void display(){
stroke(0);
strokeWeight(4);
point(pos.x,pos.y);
}
void checkEdges(){
if (pos.x > width){
pos.x = 0;
}
else if (pos.x < 0){
pos.x= width;
}
if (pos.y > height){
pos.y = 0;
}
else if (pos.y < 0){
pos.y= height;
}
}
void follow(PVector[] vArr){
normPosX = floor(pos.x/res);
normPosY = floor(pos.y/res);
//convert 2D array to a 1D array
index = (normPosX + normPosY*rowsize);
if (index < rowsize * colsize){
force = vArr[index];
}
applyForce(force);
}
}