1
1
/**
2
- * Geometry
3
- * by Marius Watz.
4
- *
5
- * Using sin/cos, blends colors, and draws a series of
2
+ * Geometry
3
+ * by Marius Watz.
4
+ *
5
+ * Using sin/cos, blends colors, and draws a series of
6
6
* rotating arcs on the screen.
7
7
*/
8
8
@@ -11,33 +11,33 @@ final int COUNT = 150;
11
11
float [] pt;
12
12
int [] style;
13
13
14
-
14
+
15
15
void setup () {
16
16
size (1024 , 768 , P3D );
17
17
background (255 );
18
18
randomSeed (100 );
19
-
19
+
20
20
pt = new float [6 * COUNT ]; // rotx, roty, deg, rad, w, speed
21
21
style = new int [2 * COUNT ]; // color, render style
22
-
22
+
23
23
// Set up arc shapes
24
24
int index = 0 ;
25
25
for (int i = 0 ; i < COUNT ; i++ ) {
26
26
pt[index++ ] = random (TAU ); // Random X axis rotation
27
27
pt[index++ ] = random (TAU ); // Random Y axis rotation
28
-
28
+
29
29
pt[index++ ] = random (60 ,80 ); // Short to quarter-circle arcs
30
30
if (random (100 ) > 90 ) {
31
31
pt[index] = floor (random (8 ,27 )) * 10 ;
32
32
}
33
-
33
+
34
34
pt[index++ ] = int (random (2 ,50 )* 5 ); // Radius. Space them out nicely
35
-
35
+
36
36
pt[index++ ] = random (4 ,32 ); // Width of band
37
37
if (random (100 ) > 90 ) {
38
38
pt[index] = random (40 ,60 ); // Width of band
39
39
}
40
-
40
+
41
41
pt[index++ ] = radians (random (5 ,30 )) / 5 ; // Speed of rotation
42
42
43
43
/*
@@ -68,103 +68,101 @@ void setup() {
68
68
}
69
69
70
70
71
- void draw () {
71
+ void draw () {
72
72
background (0 );
73
-
73
+
74
74
translate (width / 2 , height / 2 , 0 );
75
- rotateX (PI / 6 );
76
- rotateY (PI / 6 );
77
-
75
+ rotateX (PI / 6 );
76
+ rotateY (PI / 6 );
77
+
78
78
int index = 0 ;
79
79
for (int i = 0 ; i < COUNT ; i++ ) {
80
80
pushMatrix ();
81
81
rotateX (pt[index++ ]);
82
82
rotateY (pt[index++ ]);
83
-
83
+
84
84
if (style[i* 2 + 1 ] == 0 ) {
85
85
stroke (style[i* 2 ]);
86
86
noFill ();
87
87
strokeWeight (1 );
88
88
arcLine(0 , 0 , pt[index++ ], pt[index++ ], pt[index++ ]);
89
-
90
- } else if (style[i* 2 + 1 ]== 1 ) {
89
+
90
+ } else if (style[i* 2 + 1 ] == 1 ) {
91
91
fill (style[i* 2 ]);
92
92
noStroke ();
93
93
arcLineBars(0 , 0 , pt[index++ ], pt[index++ ], pt[index++ ]);
94
-
94
+
95
95
} else {
96
96
fill (style[i* 2 ]);
97
97
noStroke ();
98
98
arc (0 , 0 , pt[index++ ], pt[index++ ], pt[index++ ]);
99
99
}
100
-
100
+
101
101
// increase rotation
102
- pt[index- 5 ] += pt[index]/ 10 ;
103
- pt[index- 4 ] += pt[index++ ]/ 20 ;
104
-
102
+ pt[index- 5 ] += pt[index] / 10 ;
103
+ pt[index- 4 ] += pt[index++ ] / 20 ;
104
+
105
105
popMatrix ();
106
106
}
107
107
}
108
108
109
109
110
110
// Get blend of two colors
111
- int colorBlended(float fract,
111
+ int colorBlended(float fract,
112
112
float r, float g, float b,
113
- float r2, float g2, float b2, float a) {
114
- r2 = (r2 - r);
115
- g2 = (g2 - g);
116
- b2 = (b2 - b);
117
-
118
- return color (r + r2 * fract, g + g2 * fract, b + b2 * fract, a);
113
+ float r2, float g2, float b2, float a) {
114
+ return color (r + (r2 - r) * fract,
115
+ g + (g2 - g) * fract,
116
+ b + (b2 - b) * fract, a);
119
117
}
120
118
121
-
119
+
122
120
// Draw arc line
123
121
void arcLine (float x , float y , float degrees , float radius , float w ) {
124
122
int lineCount = floor (w/ 2 );
125
-
123
+
126
124
for (int j = 0 ; j < lineCount; j++ ) {
127
125
beginShape ();
128
126
for (int i = 0 ; i < degrees; i++ ) { // one step for each degree
129
127
float angle = radians (i);
130
- vertex (x + radius * cos (angle),
131
- y + radius * sin (angle));
128
+ vertex (x + cos (angle) * radius,
129
+ y + sin (angle) * radius );
132
130
}
133
131
endShape ();
134
132
radius += 2 ;
135
133
}
136
134
}
137
135
138
-
136
+
139
137
// Draw arc line with bars
140
138
void arcLineBars (float x , float y , float degrees , float radius , float w ) {
141
139
beginShape (QUADS );
142
140
for (int i = 0 ; i < degrees/ 4 ; i += 4 ) { // degrees, but in steps of 4
143
141
float angle = radians (i);
144
- vertex (x + radius * cos (angle),
145
- y + radius * sin (angle));
146
- vertex (x + (radius + w ) * cos (angle ),
147
- y + (radius + w ) * sin (angle ));
142
+ vertex (x + cos (angle) * radius,
143
+ y + sin (angle) * radius );
144
+ vertex (x + cos (angle ) * (radius + w ),
145
+ y + sin (angle ) * (radius + w ));
148
146
149
147
angle = radians (i+ 2 );
150
- vertex (x + (radius + w ) * cos (angle ),
151
- y + (radius + w ) * sin (angle ));
152
- vertex (x + radius * cos (angle),
153
- y + radius * sin (angle));
148
+ vertex (x + cos (angle ) * (radius + w ),
149
+ y + sin (angle ) * (radius + w ));
150
+ vertex (x + cos (angle) * radius,
151
+ y + sin (angle) * radius );
154
152
}
155
153
endShape ();
156
154
}
157
155
158
-
156
+
159
157
// Draw solid arc
160
158
void arc (float x , float y , float degrees , float radius , float w ) {
161
159
beginShape (QUAD_STRIP );
162
160
for (int i = 0 ; i < degrees; i++ ) {
163
161
float angle = radians (i);
164
- vertex (x + radius * cos (angle),
165
- y + radius * sin (angle));
166
- vertex (x + (radius + w ) * cos (angle ),
167
- y + (radius + w ) * sin (angle ));
162
+ vertex (x + cos (angle) * radius ,
163
+ y + sin (angle) * radius );
164
+ vertex (x + cos (angle ) * (radius + w ),
165
+ y + sin (angle ) * (radius + w ));
168
166
}
169
167
endShape ();
170
168
}
0 commit comments