-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spring.pde
127 lines (77 loc) · 3.09 KB
/
Spring.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public class Spring{
Node node1 ; //parent node
Node node2 ; // child node
int steps = 10;
Spring(Node node1, Node node2){
this.node1 = node1;
this.node2 = node2;
}
public void highlight(){
float LayerSpace = node1.layerSpace;
stroke(0,255,0,150);
strokeWeight(1);
noFill();
if(node1.displaySpiral == false){
bezier(node1.x, node1.y, node1.x, node1.y + LayerSpace,
node2.x, node2.y - LayerSpace, node2.x, node2.y);
}else{
PVector[] pv = new PVector[steps];
PVector centroid = node1.centroid;
float Dtheta = node2.theta - node1.theta;
float Drad = node2.rad - node1.rad;
float tSpeed = Dtheta *1.0 /steps;
float rSpeed = Drad * 1.0/steps;
for(int t=0; t<steps; t++){
pv[t] = new PVector(0.0, 0.0);
pv[t].set( centroid.x + (node1.rad + rSpeed*t) * sin(node1.theta + tSpeed*t),
centroid.y - (node1.rad + rSpeed*t) * cos(node1.theta + tSpeed*t) );
}
noFill();
beginShape();
curveVertex(pv[0].x, pv[0].y); // the first control point
for(int i=0; i<steps; i++){
curveVertex(pv[i].x, pv[i].y); // is also the start point of curve
}
curveVertex(node2.x, node2.y); // the last point of curve
curveVertex(node2.x, node2.y); // is also the last control point
endShape();
}
}
public void display(){
float LayerSpace = node1.layerSpace;
stroke(0,0,0,nodeTransp*0.5);
strokeWeight(1);
noFill();
if(node1.freq == -1){
stroke(0,0,255,map(nodeTransp,0,255,120,255));
}else if(node1.freq < minSup){
stroke(255,0,0,map(nodeTransp,0,255,120,255));
}
//draw in cartesian mode
if(node1.displaySpiral == false){
bezier(node1.x, node1.y, node1.x, node1.y + LayerSpace,
node2.x, node2.y - LayerSpace, node2.x, node2.y);
}else{
PVector[] pv = new PVector[steps];
PVector centroid = node1.centroid;
float Dtheta = node2.theta - node1.theta;
float Drad = node2.rad - node1.rad;
float tSpeed = Dtheta *1.0 /steps;
float rSpeed = Drad * 1.0/steps;
for(int t=0; t<steps; t++){
pv[t] = new PVector(0.0, 0.0);
pv[t].set( centroid.x + (node1.rad + rSpeed*t) * sin(node1.theta + tSpeed*t),
centroid.y - (node1.rad + rSpeed*t) * cos(node1.theta + tSpeed*t) );
}
noFill();
beginShape();
curveVertex(pv[0].x, pv[0].y); // the first control point
for(int i=0; i<steps; i++){
curveVertex(pv[i].x, pv[i].y); // is also the start point of curve
}
curveVertex(node2.x, node2.y); // the last point of curve
curveVertex(node2.x, node2.y); // is also the last control point
endShape();
}
}
}