forked from APCSLowell/Tendron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tendril.pde
51 lines (44 loc) · 1.19 KB
/
Tendril.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
class Tendril
{
public final static int SEG_LENGTH = 4; //length of each segment in the tendril
private int myNumSegments, myX, myY;
private double myAngle;
/**
Class constructor
len is how many segments in this tendril (each a fixed length, 4 is a good start)
theta is tendril starting angle in radians
x, y is the starting (x,y) coordinate
*/
public Tendril(int len, double theta, int x, int y)
{
myNumSegments = len;
myAngle = theta;
myX = x;
myY = y;
}
public void show()
{
int startX = myX;
int startY = myY;
if(myNumSegments >= 100){
stroke(5, 223, 227);
}else if(myNumSegments >= 30){
stroke(3, 44, 252);
}else if(myNumSegments >= 10){
stroke(148, 0, 189);
}else {
stroke(242, 29, 207);
}
for(int i = 0; i < myNumSegments; i++){
myAngle += Math.random()*0.4 - 0.2;
int endX = startX + (int)(SEG_LENGTH*Math.cos(myAngle));
int endY = startY + (int)(SEG_LENGTH*Math.sin(myAngle));
line(startX, startY, endX, endY);
startX = endX;
startY = endY;
}
if(myNumSegments > 10){
Cluster newC = new Cluster(myNumSegments / 3, startX, startY);
}
}
}