-
Notifications
You must be signed in to change notification settings - Fork 0
/
serpientemagica.pde
268 lines (234 loc) · 6.14 KB
/
serpientemagica.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// MAGIC SERPENT - THAT TOY CONSISTENT ON SMALL PRISMS JOINED BY THEIR SQUARE FACES-
//Probando a hacer triángulos para la serpiente mágica
//La serpiente tiene 24 triángulos (12 verdes y 12 blancos)
//cada triángulo: rotateX (HALF_PI), rotateY(PI), translate (200,0,0).
//(suponiendo el tamaño 100);
// For android support, replace the double-slash slash-asterisk ANDROID asteris-slash with empty space.
///*ANDROID */ import android.view.KeyEvent;
boolean debugging=false;
boolean demo=true;
boolean gui=true;
Prisma verde,verdeH;
Prisma blanco,blancoH;
/*int anguloprisma[]={
1,1,1,1,
-1,-1,-1,-1,
1,1,1,1,
-1,-1,-1,-1,
1,1,1,1,
-1,-1,-1,-1
}; //bola
*/
/*
int anguloprisma[]={
1,1,1,1,
3,0,0,0,
0,0,0,3,
1,1,1,1,
3,0,0,0,
0,0,0,3
}; //hueso
*//*
int anguloprisma[]={
1,1,1,1,
3,2,0,2,
2,0,2,3,
1,1,1,1,
3,2,0,2,
2,0,2,3
}; //cruz rara
*//*
int anguloprisma[]={
1,1,1,1,3,1,1,3,
1,1,1,1,3,1,1,3,
1,1,1,1,3,1,1,3
} ; //roseta
*/
int anguloprisma[]={
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0
} ; //recto
int iprisma=0;
class Prisma{
public PShape shape;
PShape prism;
PShape quads;
PShape triangles;
public color Pcolor;
public color Pstroke;
Prisma(color fillColor, color strokeColor){
Pcolor=fillColor;
Pstroke=strokeColor;
prism=createShape(GROUP);
quads=createShape();
quads.beginShape(QUADS);
quads.fill(fillColor);
quads.stroke(strokeColor);
quads.vertex(-100,100,-100);
quads.vertex(100,100,-100);
quads.vertex(100,-100,-100);
quads.vertex(-100,-100,-100);
////base2;
quads.vertex(-100,-100,-100);
quads.vertex(-100,-100,100);
quads.vertex(-100,100,100);
quads.vertex(-100,100,-100);
//rectángulo hipotenusa
quads.vertex(100,100,-100);
quads.vertex(-100,100,100);
quads.vertex(-100,-100,100);
quads.vertex(100,-100,-100);
quads.endShape(CLOSE);
triangles=createShape();
//t1
triangles.beginShape(TRIANGLES);
triangles.fill(fillColor);
triangles.stroke(strokeColor);
triangles.vertex(-100,100,-100);
triangles.vertex(-100,100,100);
triangles.vertex(100,100,-100);
//t2
triangles.vertex(-100,-100,-100);
triangles.vertex(-100,-100,100);
triangles.vertex(100,-100,-100);
triangles.endShape(CLOSE);
prism.addChild(quads);
prism.addChild(triangles);
}
void draw(){
shape(prism);
}
}
void setup(){
size(displayWidth,displayHeight,P3D);
colorMode(RGB);
verde=new Prisma(color(0,128,0), color(0,0,0));
verdeH=new Prisma(color(0,255,0),color(255,255,255));
blanco=new Prisma(color(128,128,128),color(0,0,0));
blancoH=new Prisma(color(255,255,255),color(0,255,0));
if (gui) guiSetup();
if (demo) demoSetup();
}
float angX=0,angY=0;
float angZ=0;
float tX=0,tY=0,tZ=0;
void draw(){
int f;
if (debugging) { iprisma=4; }
background(80,80,150);
guiDraw();
if (debugging) {
textSize (16);
text (str(angX),10,10);
text (str(angY),10,30);
text (str(angZ),10,50);
text(str(tX),100,10);
text(str(tY),100,30);
text(str(tZ),100,50);
text(str(iprisma),100,70);
}
if (demo) { demoDraw(); }
textSize (min (height/25, width/30));
text("Fórmula: ",10,height*0.90);
for (f=0;f<anguloprisma.length;f++){
anguloprisma[f]=(anguloprisma[f]+4) % 4;
text(str(anguloprisma[f])+"/",textWidth ("Fórmula: ")+f*textWidth("4/"),height*0.90);
}
//beginCamera();
translate(width/2,height/2,-500);
rotate(TWO_PI*frameCount/360);
//rotateY(-QUARTER_PI);
rotateX(TWO_PI*frameCount/360);
//Guardamos la posición del prisma activo.
pushMatrix();
//Dibujamos desde el prisma activo hasta el final.
for (f=iprisma;f<anguloprisma.length;f++){
if (f % 2==0) {
if (iprisma==f) { verdeH.draw(); } else { verde.draw(); }
rotate(HALF_PI*anguloprisma[f]);
} else {
if (iprisma==f) { blancoH.draw(); } else { blanco.draw(); }
rotate(-HALF_PI*anguloprisma[f]);
}
rotateX(-PI);
rotateY(-HALF_PI);
translate(200.0,0.0,0.0);
}
//Volvemos al prisma activo y giramos del revés
//para dibujar los prismas anteriores.
popMatrix();
rotate(-PI);
rotateX(PI);
translate(200,0,0);
if (debugging) {
rotateX (angX*HALF_PI);
rotateY (angY*HALF_PI);
rotate(angZ*HALF_PI);
translate(tX,tY,tZ);
}
for (f=iprisma-1;f>=0;f--){
if (f % 2==0) {
rotateX(-HALF_PI*anguloprisma[f]);
verde.draw();
} else {
rotateX(HALF_PI*anguloprisma[f]);
blanco.draw();
}
rotateX(-PI);
rotateY(-HALF_PI);
translate(200.0,0.0,0.0);
}
//endCamera();
}
void keyPressed(){
if (demo) {
demo=false;
}
if (debugging) {
switch(key){
case 'X': angX++; break;
case 'x': angX--; break;
case 'Y': angY++; break;
case 'y': angY--; break;
case 'Z': angZ++; break;
case 'z': angZ--; break;
case '+':tZ+=100.0; break;
case '-':tZ-=100.0;break;
}
switch(keyCode){
case UP:tY+=100.0; break;
case DOWN: tY-=100.0; break;
case LEFT: tX-=100.0;break;
case RIGHT: tX+=100.0;break;
}
} else {
switch(keyCode){
case LEFT:
///*ANDROID */ case android.view.KeyEvent.KEYCODE_VOLUME_UP:
iprisma++;
break;
case RIGHT:
///*ANDROID */case android.view.KeyEvent.KEYCODE_VOLUME_DOWN:
iprisma--;
break;
case UP:
///*ANDROID */ case MENU:
anguloprisma[iprisma]++;
if (anguloprisma[iprisma]>=4){ anguloprisma[iprisma]=0; }
break;
case DOWN:
anguloprisma[iprisma]--;
if (anguloprisma[iprisma]<0){ anguloprisma[iprisma]=3;}
break;
}
if (iprisma<0) iprisma=anguloprisma.length-1;
if (iprisma>=anguloprisma.length) iprisma=anguloprisma.length-1;
}
}
void centerText(String t, float y){
textAlign(CENTER);
text(t,(width)/2,y);
textAlign(RIGHT);
}