-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNode.pde
More file actions
40 lines (33 loc) · 748 Bytes
/
Node.pde
File metadata and controls
40 lines (33 loc) · 748 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
class Node extends PVector{
PVector velocity = new PVector();
float minX = 65, minY = 30, maxY = height-30, maxX = width - 65;
float damping = 0.1;
Node(float theX, float theY){
x = theX;
y = theY;
}
void update(){
x += velocity.x+random(-3,3);
y += velocity.y+random(-3,3);
//X
if (x < minX) {
x = minX - (x-minX);
velocity.x = -velocity.x;
}
if (x > maxX) {
x = maxX - (x-maxX);
velocity.x = -velocity.x;
}
//Y
if (y < minY) {
y = minY - (y-minY);
velocity.y = -velocity.y;
}
if (y > maxY) {
y = maxY - (y-maxY);
velocity.y = -velocity.y;
}
velocity.x *= (1-damping);
velocity.y *= (1-damping);
}
}