-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSacredFlower.pde
150 lines (124 loc) · 4.19 KB
/
SacredFlower.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
class SacredFlower {
// Dimensions of Geometry
private float sized;
private int depth;
// Mutable colors range
color shakra = color(255, 255, 255);
// Sacred Circle Storage
ArrayList<SacredCircle> circles = new ArrayList<SacredCircle>();
// Center Sacred Circle
SacredCircle center;
// Edge Cardinal Circles
SacredCircle n, nw, sw, s, se, ne;
SacredCircle[] edgeCardinals = new SacredCircle[6];
// Factory Init
SacredFlower(float _x, float _y, float _sized, int _depth) {
sized = _sized;
depth = _depth;
// Center Circle
center = new SacredCircle(new SacredPoint(_x, _y), circleDiameter());
circles.add(center);
// Iterate for depth
for (int d = 1; d < depth; d++) {
// Iterate for cardinal points
for (int i = 0; i < 6; i++) {
// Distance from center point
float radius = (circleRadius() * float(d));
// Cardinal circle at depth
SacredCircle circle = new SacredCircle(centerPoint(radius, radiansForI(i)), circleDiameter());
circles.add(circle);
// Next circle (for calculation)
SacredCircle next = new SacredCircle(centerPoint(radius, radiansForI(i+1)), circleDiameter());
// Iterate for filler circles between current and next cardinal circles
for (int f = 1; f <= d-1; f++) {
float delta = float(f)/float(d);
SacredCircle filler = new SacredCircle(centerPoint(circle, next, delta), circleDiameter());
circles.add(filler);
}
// Is edge cardinal circle?
if (d == depth-1) {
edgeCardinals[i] = circle;
}
}
}
}
// Cardinal Circle Center Generator
private SacredPoint centerPoint(float radius, float radian) {
float x = center.center.x + (radius * cos(radian));
float y = center.center.y + (radius * sin(radian));
return new SacredPoint(x, y);
}
// Delta Circle Center Generator
private SacredPoint centerPoint(SacredCircle current, SacredCircle next, float delta) {
float x = current.center.x - ((current.center.x - next.center.x) * delta);
float y = current.center.y - ((current.center.y - next.center.y) * delta);
return new SacredPoint(x, y);
}
// Draws the Sacred Geometry, draw loop
void drawGeometry(SacredArduino arduino) {
noFill();
for (SacredCircle circle : circles) {
float vibrance = 0.0;
for (int i = 0; i < 6; i++) {
SacredCircle cardinal = edgeCardinals[i];
float vib = 0.0;
vib += potentialVibranceForCircles(circle, cardinal);
vib *= arduino.vibranceForIndex(i);
vibrance += vib;
circle.drawCircleVibrance(shakra, min(vibrance, 1.0));
}
}
}
void drawGeometry(color c) {
noFill();
for (SacredCircle circle : circles) {
circle.drawCircle(c);
}
}
void drawGeometry() {
noFill();
for (SacredCircle circle : circles) {
circle.drawCircle();
}
}
void drawGeometryRandom() {
noFill();
for (SacredCircle circle : circles) {
circle.drawCircleRandom();
}
}
private float radiansForI(int i) {
return radians(degreesForI(i));
}
private float degreesForI(int i) {
return (30.0 + (float(i+1) * 60.0)); // start at 90
}
private float circleDiameter() {
return sized / float(depth);
}
private float circleRadius() {
return (circleDiameter() / 2.0);
}
// TODO
private float maxVibranceDistance() {
return ((float(depth) - 1.0) * circleRadius()) + circleRadius();
}
private float minVibranceEffect() {
return 1.0 / 6.0;
}
private float potentialVibranceForCircles(SacredCircle curr, SacredCircle card) {
float actualDistance = curr.distanceFrom(card);
float lowestDistance = 0.0;
float highestDistance = maxVibranceDistance();
if (actualDistance > highestDistance) {
return 0.0;
}
float lowestVibrance = minVibranceEffect();
float highestVibrance = 1.0;
//println(actualDistance + " " + lowestDistance + " " + highestDistance + " " + lowestVibrance + " " + highestVibrance);
float pVib = map(actualDistance, lowestDistance, highestDistance, lowestVibrance, highestVibrance);
//println(pVib);
//print("\n");
return 1.0 - pVib;
}
}