-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAngleList.pde
131 lines (117 loc) · 2.87 KB
/
AngleList.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
128
129
130
131
class AngleList
{
int totalSectors;
int totalSets;
int perlinNoiseDetail = 3;
String type;
FloatList angles = new FloatList();
float minimumAngle = radians(2);
AngleList(int _totalSectors, String _type)
{
type = _type;
if (type == "set") {
totalSectors = setAngleList.size();
} else {
totalSectors = _totalSectors;
}
totalSets = totalSectors / 2;
calculateAngles();
}
void calculateAngles()
{
switch (type)
{
case "uniform":
calculateUniformAngles();
break;
case "random":
calculateRandomAngles();
break;
case "perlin":
calculatePerlinAngles();
break;
case "parametric":
calculateParametricAngles();
break;
case "fibonacci":
calculateFibonacciAngles();
break;
case "set":
angles = setAngleList;
break;
}
makeCyclical();
}
void calculateUniformAngles()
{
for (int i = 0; i < totalSectors; i++)
{
angles.append(TWO_PI / totalSectors);
}
}
void calculateRandomAngles()
{
for (int i = 0; i < totalSectors; i++)
{
angles.append(random(1));
}
}
void calculatePerlinAngles()
{
noiseDetail(perlinNoiseDetail);
for (int i = 0; i < totalSectors; i++)
{
angles.append(noise(i));
}
}
void calculateParametricAngles()
{
for (int i = 0; i < totalSets; i++)
{
angles.append(1 - cos((2 * i) * TWO_PI / totalSectors));
angles.append(1 - cos((2 * i + 1) * TWO_PI / totalSectors));
}
}
void calculateFibonacciAngles()
{
int current = 2;
int previous = 1;
for (int i = 0; i < totalSets; i++)
{
if (i > 1) {
current += previous;
previous = current - previous;
}
angles.append(previous);
angles.append(current);
}
angles.shuffle();
}
void makeCyclical()
{
float[] clockwiseAngles = new float[totalSets];
float[] anticlockwiseAngles = new float[totalSets];
float fullCycle = (totalRotations * TWO_PI) - (totalSectors * minimumAngle);
float clockwiseMultiplier = 0;
float anticlockwiseMultiplier = 0;
for (int i = 0; i < totalSets; i++)
{
clockwiseAngles[i] = angles.get(2 * i);
anticlockwiseAngles[i] = angles.get(2 * i + 1);
clockwiseMultiplier += clockwiseAngles[i];
anticlockwiseMultiplier += anticlockwiseAngles[i];
}
clockwiseMultiplier = (fullCycle / 2) / clockwiseMultiplier;
anticlockwiseMultiplier = (fullCycle / 2) / anticlockwiseMultiplier;
angles = new FloatList();
for (int i = 0; i < totalSets; i++)
{
angles.append(minimumAngle + (clockwiseAngles[i] * clockwiseMultiplier));
angles.append(minimumAngle + (anticlockwiseAngles[i] * anticlockwiseMultiplier));
}
}
void printAngles()
{
println(angles);
}
}