-
Notifications
You must be signed in to change notification settings - Fork 2
/
spirograph.pde
243 lines (209 loc) · 5.87 KB
/
spirograph.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
class Spirograph {
float x;
float y;
float xpos;
float ypos;
float angulo_fijo = 0;
float angulo=0;
float size,modulo,inc;
float size2;
boolean colormanual;
float hue, sat, bri, trans;
float Bsize, Bhue, Bsat, Bbri, Btrans ;
boolean israndom = false;;
int npoints = 8;
//Booleanos que indican para que lado debe moverse
boolean moveX;
boolean moveY;
boolean starorpoly;
float speedX;
float speedY;
Spirograph(/*Variables de posición */ float tempxpos,float tempypos,
/*Variables de movimiento */ float tempsize, float tempmodulo, float tempinc,
/*Variables de color */ boolean tempcolormanual, float temphue, float tempsat, float tempbri, float temptrans,
/*Variables del borde*/ float tempBsize, float tempBhue, float tempBsat, float tempBbri, float tempBtrans,
/*Efecto random y puntas del poligono */ boolean tempisrandom, int tempnpoints ){
xpos = tempxpos;
ypos = tempypos;
size = tempsize;
modulo = tempmodulo;
inc = tempinc;
colormanual = tempcolormanual;
hue = temphue;
sat = tempsat;
bri = tempbri;
trans = temptrans;
Bsize = tempBsize;
Bhue = tempBhue;
Bsat = tempBsat;
Bbri = tempBbri;
Btrans = tempBtrans;
israndom = tempisrandom;
npoints = tempnpoints;
}
void setSettings(float Csize,float _size2, float Cmodulo, float Cinc
,boolean Ccolormanual,float Chue,float Csat,float Cbri, float Ctrans
,float CBsize, float CBhue, float CBsat, float CBbri,float CBtrans
,boolean Cisrandom,int Cnpoints,boolean _starorpoly,float _speedX,float _speedY){
size = Csize;
size2 = _size2;
modulo = Cmodulo;
inc = Cinc;
colormanual = Ccolormanual;
hue = Chue;
sat = Csat;
bri = Cbri;
trans = Ctrans;
Bsize = CBsize;
Bhue = CBhue;
Bsat = CBsat;
Bbri = CBbri;
Btrans = CBtrans;
israndom =Cisrandom;
npoints = Cnpoints;
starorpoly = _starorpoly;
speedX = _speedX;
speedY = _speedY;
}
void display()
{
setBorde();
setColor();
pushMatrix();
angulo_fijo+=inc; //Cuanto mayor sea inc, mas sera el efecto espirografico.
angulo= angulo -10;
x=(cos(radians(-(angulo)))*modulo);
y=(sin(radians(-(angulo)))*modulo);
translate(this.xpos - modulo +x, this.ypos -y);
rotate(radians( angulo_fijo )); //Este rotate genera el efecto espirografico.
if (keyPressed && key == 'k'){
angulo = 0;
angulo_fijo = 0;
}
if(israndom){
//polygon(modulo+modulo/2,modulo-modulo/2,size,npoints);
//star(modulo+modulo/2,modulo-modulo/2,size,size2,npoints);
starOrpolygon(starorpoly);
}
else {
//polygon(modulo+modulo/2,modulo-modulo/2,size,npoints);
// star(modulo+modulo/2,modulo-modulo/2,size,size2,npoints);
starOrpolygon(starorpoly);
}
popMatrix();
}
void setColor() {
if (colormanual){
fill(hue,sat,bri,trans);
}
else{
fill(col,255,255,trans);
col++;
if (col == 255) {
col = 0 ;
}
}
}
void setPos(float tempxpos,float tempypos) {
xpos = tempxpos;
ypos = tempypos;
}
void move(){
if (xpos >= width || xpos <= 0){
moveX = !moveX;
}
if (ypos >= height || ypos <= 0){
moveY = !moveY;
}
if (moveX){
xpos += speedX;
}
else {
xpos -= speedX;
}
if (moveY){
ypos += speedY;
}
else {
ypos -= speedY;
}
}
void setBorde(){
stroke(Bhue,Bsat,Bbri,Btrans);
strokeWeight(Bsize);
}
void starOrpolygon(boolean starorpoly){
if (starorpoly){
star(modulo+modulo/2,modulo-modulo/2,size,size2,npoints);
}
else {
polygon(modulo+modulo/2, modulo-modulo/2, size,npoints);
}
}
void polygon(float x, float y, float radius, int npoints) {
if (npoints <= 1){
if(israndom){
ellipse(modulo+modulo/2,modulo-modulo/2,random(size),random(size));
}
else{
ellipse(modulo+modulo/2,modulo-modulo/2,size,size);
}
}
if (npoints == 2 ) {
strokeWeight(Bsize);
line(modulo+modulo/2, modulo+modulo/2,size, size);
}
else if(npoints == 4){
if(israndom){
rect(modulo+modulo/2,modulo-modulo/2,random(size),random(size));
}
else{
rect(modulo+modulo/2,modulo-modulo/2,size,size);
}
}
else {
if(israndom){
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(random(sx), random(sy));
}
endShape(CLOSE);
}
else{
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
}
}
void star(float x, float y, float radius1, float radius2, int npoints) {
if (npoints == 1){
npoints = 2;
}
float angle = TWO_PI / npoints;
float halfAngle = angle/2.0;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius2;
float sy = y + sin(a) * radius2;
if (israndom){
vertex(random(sx), random(sy));
}
else{
vertex(sx, sy);
}
sx = x + cos(a+halfAngle) * radius1;
sy = y + sin(a+halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
}