Skip to content

Commit 9391a75

Browse files
committed
more cleaning for legibility
1 parent 1b3df86 commit 9391a75

File tree

1 file changed

+47
-49
lines changed

1 file changed

+47
-49
lines changed
Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
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
66
* rotating arcs on the screen.
77
*/
88

@@ -11,33 +11,33 @@ final int COUNT = 150;
1111
float[] pt;
1212
int[] style;
1313

14-
14+
1515
void setup() {
1616
size(1024, 768, P3D);
1717
background(255);
1818
randomSeed(100);
19-
19+
2020
pt = new float[6 * COUNT]; // rotx, roty, deg, rad, w, speed
2121
style = new int[2 * COUNT]; // color, render style
22-
22+
2323
// Set up arc shapes
2424
int index = 0;
2525
for (int i = 0; i < COUNT; i++) {
2626
pt[index++] = random(TAU); // Random X axis rotation
2727
pt[index++] = random(TAU); // Random Y axis rotation
28-
28+
2929
pt[index++] = random(60,80); // Short to quarter-circle arcs
3030
if (random(100) > 90) {
3131
pt[index] = floor(random(8,27)) * 10;
3232
}
33-
33+
3434
pt[index++] = int(random(2,50)*5); // Radius. Space them out nicely
35-
35+
3636
pt[index++] = random(4,32); // Width of band
3737
if (random(100) > 90) {
3838
pt[index] = random(40,60); // Width of band
3939
}
40-
40+
4141
pt[index++] = radians(random(5,30)) / 5; // Speed of rotation
4242

4343
/*
@@ -68,103 +68,101 @@ void setup() {
6868
}
6969

7070

71-
void draw() {
71+
void draw() {
7272
background(0);
73-
73+
7474
translate(width/2, height/2, 0);
75-
rotateX(PI/6);
76-
rotateY(PI/6);
77-
75+
rotateX(PI / 6);
76+
rotateY(PI / 6);
77+
7878
int index = 0;
7979
for (int i = 0; i < COUNT; i++) {
8080
pushMatrix();
8181
rotateX(pt[index++]);
8282
rotateY(pt[index++]);
83-
83+
8484
if (style[i*2+1] == 0) {
8585
stroke(style[i*2]);
8686
noFill();
8787
strokeWeight(1);
8888
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) {
9191
fill(style[i*2]);
9292
noStroke();
9393
arcLineBars(0, 0, pt[index++], pt[index++], pt[index++]);
94-
94+
9595
} else {
9696
fill(style[i*2]);
9797
noStroke();
9898
arc(0, 0, pt[index++], pt[index++], pt[index++]);
9999
}
100-
100+
101101
// 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+
105105
popMatrix();
106106
}
107107
}
108108

109109

110110
// Get blend of two colors
111-
int colorBlended(float fract,
111+
int colorBlended(float fract,
112112
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);
119117
}
120118

121-
119+
122120
// Draw arc line
123121
void arcLine(float x, float y, float degrees, float radius, float w) {
124122
int lineCount = floor(w/2);
125-
123+
126124
for (int j = 0; j < lineCount; j++) {
127125
beginShape();
128126
for (int i = 0; i < degrees; i++) { // one step for each degree
129127
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);
132130
}
133131
endShape();
134132
radius += 2;
135133
}
136134
}
137135

138-
136+
139137
// Draw arc line with bars
140138
void arcLineBars(float x, float y, float degrees, float radius, float w) {
141139
beginShape(QUADS);
142140
for (int i = 0; i < degrees/4; i += 4) { // degrees, but in steps of 4
143141
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));
148146

149147
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);
154152
}
155153
endShape();
156154
}
157155

158-
156+
159157
// Draw solid arc
160158
void arc(float x, float y, float degrees, float radius, float w) {
161159
beginShape(QUAD_STRIP);
162160
for (int i = 0; i < degrees; i++) {
163161
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));
168166
}
169167
endShape();
170168
}

0 commit comments

Comments
 (0)