Skip to content

Commit 5d5066b

Browse files
committed
removing lookup and the completely unused block
1 parent 96f5c6e commit 5d5066b

File tree

1 file changed

+87
-69
lines changed

1 file changed

+87
-69
lines changed

Demos/Graphics/RotatingArcs/RotatingArcs.pde

100755100644
Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,29 @@
55
* Using sin/cos lookup tables, blends colors, and draws a series of
66
* rotating arcs on the screen.
77
*/
8-
9-
// Trig lookup tables borrowed from Toxi; cryptic but effective.
10-
float sinLUT[];
11-
float cosLUT[];
12-
float SINCOS_PRECISION=1.0;
13-
int SINCOS_LENGTH= int((360.0/SINCOS_PRECISION));
14-
15-
// System data
16-
boolean dosave=false;
17-
int num;
18-
float pt[];
19-
int style[];
8+
9+
final int COUNT = 150;
10+
11+
float[] pt;
12+
int[] style;
2013

2114

2215
void setup() {
2316
size(1024, 768, P3D);
2417
background(255);
18+
randomSeed(100);
2519

26-
// Fill the tables
27-
sinLUT=new float[SINCOS_LENGTH];
28-
cosLUT=new float[SINCOS_LENGTH];
29-
for (int i = 0; i < SINCOS_LENGTH; i++) {
30-
sinLUT[i]= (float)Math.sin(i*DEG_TO_RAD*SINCOS_PRECISION);
31-
cosLUT[i]= (float)Math.cos(i*DEG_TO_RAD*SINCOS_PRECISION);
32-
}
33-
34-
num = 150;
35-
pt = new float[6*num]; // rotx, roty, deg, rad, w, speed
36-
style = new int[2*num]; // color, render style
20+
pt = new float[6 * COUNT]; // rotx, roty, deg, rad, w, speed
21+
style = new int[2 * COUNT]; // color, render style
3722

3823
// Set up arc shapes
39-
int index=0;
40-
float prob;
41-
for (int i=0; i<num; i++) {
42-
pt[index++] = random(PI*2); // Random X axis rotation
43-
pt[index++] = random(PI*2); // Random Y axis rotation
24+
int index = 0;
25+
for (int i = 0; i < COUNT; i++) {
26+
pt[index++] = random(TAU); // Random X axis rotation
27+
pt[index++] = random(TAU); // Random Y axis rotation
4428

4529
pt[index++] = random(60,80); // Short to quarter-circle arcs
46-
if(random(100)>90) pt[index]=(int)random(8,27)*10;
30+
if(random(100)>90) pt[index] = floor(random(8,27)) * 10;
4731

4832
pt[index++] = int(random(2,50)*5); // Radius. Space them out nicely
4933

@@ -53,30 +37,40 @@ void setup() {
5337
pt[index++] = radians(random(5,30))/5; // Speed of rotation
5438

5539
// get colors
56-
prob = random(100);
57-
if(prob<30) style[i*2]=colorBlended(random(1), 255,0,100, 255,0,0, 210);
58-
else if(prob<70) style[i*2]=colorBlended(random(1), 0,153,255, 170,225,255, 210);
59-
else if(prob<90) style[i*2]=colorBlended(random(1), 200,255,0, 150,255,0, 210);
60-
else style[i*2]=color(255,255,255, 220);
40+
float prob = random(100);
41+
42+
//if (prob < 30) {
43+
// style[i*2] = colorBlended(random(1), 255,0,100, 255,0,0, 210);
44+
//} else if (prob < 70) {
45+
// style[i*2] = colorBlended(random(1), 0,153,255, 170,225,255, 210);
46+
//} else if (prob < 90) {
47+
// style[i*2] = colorBlended(random(1), 200,255,0, 150,255,0, 210);
48+
//} else {
49+
// style[i*2] = color(255,255,255, 220);
50+
//}
6151

62-
if(prob<50) style[i*2]=colorBlended(random(1), 200,255,0, 50,120,0, 210);
63-
else if(prob<90) style[i*2]=colorBlended(random(1), 255,100,0, 255,255,0, 210);
64-
else style[i*2]=color(255,255,255, 220);
52+
if (prob < 50) {
53+
style[i*2] = colorBlended(random(1), 200,255,0, 50,120,0, 210);
54+
} else if (prob <90) {
55+
style[i*2] = colorBlended(random(1), 255,100,0, 255,255,0, 210);
56+
} else {
57+
style[i*2] = color(255,255,255, 220);
58+
}
6559

66-
style[i*2+1]=(int)(random(100))%3;
60+
style[i*2+1] = floor(random(100)) % 3;
6761
}
6862
}
69-
70-
void draw() {
71-
63+
64+
65+
void draw() {
7266
background(0);
7367

7468
int index=0;
7569
translate(width/2, height/2, 0);
7670
rotateX(PI/6);
7771
rotateY(PI/6);
7872

79-
for (int i = 0; i < num; i++) {
73+
for (int i = 0; i < COUNT; i++) {
8074
pushMatrix();
8175

8276
rotateX(pt[index++]);
@@ -100,63 +94,87 @@ void draw() {
10094
}
10195

10296
// increase rotation
103-
pt[index-5]+=pt[index]/10;
104-
pt[index-4]+=pt[index++]/20;
97+
pt[index-5] += pt[index]/10;
98+
pt[index-4] += pt[index++]/20;
10599

106100
popMatrix();
107101
}
102+
if (frameCount == 100) {
103+
saveFrame("newer.png");
104+
exit();
105+
}
108106
}
109-
110-
107+
108+
111109
// Get blend of two colors
112-
int colorBlended(float fract,
113-
float r, float g, float b,
114-
float r2, float g2, float b2, float a) {
115-
110+
int colorBlended(float fract,
111+
float r, float g, float b,
112+
float r2, float g2, float b2, float a) {
116113
r2 = (r2 - r);
117114
g2 = (g2 - g);
118115
b2 = (b2 - b);
116+
119117
return color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a);
120118
}
121-
119+
122120

123121
// Draw arc line
124-
void arcLine(float x,float y,float deg,float rad,float w) {
125-
int a=(int)(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
122+
void arcLine(float x,float y,float degrees,float radius,float w) {
123+
//int a=(int)(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
126124
int numlines=(int)(w/2);
127125

128126
for (int j=0; j<numlines; j++) {
129127
beginShape();
130-
for (int i=0; i<a; i++) {
131-
vertex(cosLUT[i]*rad+x,sinLUT[i]*rad+y);
128+
for (int i = 0; i < degrees; i++) { // one step for each degree
129+
float angle = radians(i);
130+
//vertex(cosLUT[i]*rad+x,sinLUT[i]*rad+y);
131+
vertex(x + radius*cos(angle), y + radius*sin(angle));
132132
}
133133
endShape();
134-
rad += 2;
134+
radius += 2;
135135
}
136136
}
137+
137138

138139
// Draw arc line with bars
139-
void arcLineBars(float x,float y,float deg,float rad,float w) {
140-
int a = int((min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1)));
141-
a /= 4;
140+
void arcLineBars(float x, float y,float degrees, float radius, float w) {
141+
//int a = int((min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1)));
142+
//a /= 4;
142143

143144
beginShape(QUADS);
144-
for (int i=0; i<a; i+=4) {
145-
vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
146-
vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
147-
vertex(cosLUT[i+2]*(rad+w)+x,sinLUT[i+2]*(rad+w)+y);
148-
vertex(cosLUT[i+2]*(rad)+x,sinLUT[i+2]*(rad)+y);
145+
//for (int i=0; i<a; i+=4) {
146+
for (int i = 0; i < degrees/4; i += 4) { // degrees, but in steps of 4
147+
float angle = radians(i);
148+
//vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
149+
vertex(x + radius*cos(angle),
150+
y + radius*sin(angle));
151+
//vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
152+
vertex(x + (radius+w) * cos(angle),
153+
y + (radius+w) * sin(angle));
154+
angle = radians(i+2);
155+
//vertex(cosLUT[i+2]*(rad+w)+x,sinLUT[i+2]*(rad+w)+y);
156+
vertex(x + (radius+w) * cos(angle),
157+
y + (radius+w) * sin(angle));
158+
//vertex(cosLUT[i+2]*(rad)+x,sinLUT[i+2]*(rad)+y);
159+
vertex(x + radius*cos(angle),
160+
y + radius*sin(angle));
149161
}
150162
endShape();
151163
}
164+
152165

153166
// Draw solid arc
154-
void arc(float x,float y,float deg,float rad,float w) {
155-
int a = int(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
167+
void arc(float x, float y, float degrees, float radius, float w) {
168+
//int a = int(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
156169
beginShape(QUAD_STRIP);
157-
for (int i = 0; i < a; i++) {
158-
vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
159-
vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
170+
for (int i = 0; i < degrees; i++) {
171+
float angle = radians(i);
172+
//vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
173+
vertex(x + radius*cos(angle),
174+
y + radius*sin(angle));
175+
//vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
176+
vertex(x + (radius+w)*cos(angle),
177+
y + (radius+w)*sin(angle));
160178
}
161179
endShape();
162180
}

0 commit comments

Comments
 (0)