-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.pde
More file actions
94 lines (72 loc) · 1.64 KB
/
Node.pde
File metadata and controls
94 lines (72 loc) · 1.64 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Node
class Node {
float x;
float y;
float size;
ArrayList<Route> routes;
float growthRate;
Node() {
// x = random(0, displayWidth);
// y = random(0, displayHeight);
size = random(3, 24);
growthRate = random(0.75, 1.45);
routes = new ArrayList<Route>();
// distances = new float[numNodes];
}
void update(float t) {
// t = time
//size = size + (size * t * (growthRate-1.0));
// println(size);
//check routes
for (Route route : routes) {
if (route.connection.active) {
if(random(0,1)>0.95){
float sizeDiff = this.size - route.destination.size;
if (sizeDiff > minCharge) {
float mass = min(sizeDiff,maxBlipSize);
route.addChargeOfMass(mass);
this.size = this.size - mass;
}
}
}
// route.update();
}
}
void display() {
ellipseMode(CENTER);
//
if (dist(mouseX, mouseY, x, y)<size) {
stroke(#ff0000, 255);
}
else {
stroke(#ffff00, 127);
}
strokeWeight(2.0);
fill(#ffffff, 250);
ellipse(x, y, size, size);
noStroke();
if (dist(mouseX, mouseY, x, y)<size) {
fill(#ffff77, 250);
for (Route route:routes) {
route.connection.active = true;
}
}
else {
fill(#777700, 250);
}
ellipse(x, y, size/2, size/2);
}
float getDistanceTo(Node n) {
return(sqrt((this.x-n.x)*(this.x-n.x)+(this.y-n.y)*(this.y-n.y)));
}
Route connectTo(Node n) {
Route r = new Route(this, n);
routes.add(r);
return r;
}
Point point() {
return new Point(x, y);
}
void sortDistances() {
}
}