-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSphere.pde
67 lines (58 loc) · 1.78 KB
/
Sphere.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
int sphereSize, sphereStroke, sphereFill, spinMult = 1;
float shakeX, shakeY, spinSphereX, spinSphereZ;
boolean shake, sphereOn, sphereVar;
// Supersphere
PVector[][] superSphere;
int superSphereTotal = 20;
void mySphere() {
translate(0, height * 2/3, 125);
//sphereDetail(20);
stroke(sphereStroke);
fill(sphereFill);
if (sphereSize > (120)) { // Reduce to stable
sphereSize *= 0.97;
}
rotateZ(radians(spinSphereZ)); // Slowly rotate the sphere
spinSphereZ += 0.5 * spinMult;
if (shake) { // Activate shaky effect.
translate(random(10), random(10));
}
//sphere(sphereSize); // Draw sphere
if (superSphereTotal < 20 && !sphereVar) superSphereTotal++;
int total = superSphereTotal;
float r = sphereSize;
for (int i = 0; i < total+1; i++) {
float lat = map(i, 0, total, 0, PI);
for (int j = 0; j < total+1; j++) {
float lon = map(j, 0, total, 0, TWO_PI);
float x = r * sin(lat) * cos(lon);
float y = r * sin(lat) * sin(lon);
float z = r * cos(lat);
superSphere[i][j] = new PVector(x, y, z);
}
}
for (int i = 0; i < total; i++) {
//float red = map(i, 0, total, 255, 0);
//float green = map(i, 0, total, 0, 255);
//float blue = 0;
//stroke(red, green, blue, 255);
//fill(red, green, blue, 127);
beginShape(TRIANGLE_STRIP);
for (int j = 0; j < total+1; j++) {
PVector v1 = superSphere[i][j];
vertex(v1.x, v1.y, v1.z);
PVector v2 = superSphere[i+1][j];
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
}
void explode() {
noStroke();
fill(255, explodeGreen, 0, explodeAlpha);
ellipse(0, 0, radius, radius);
radius += 50;
if (explodeAlpha > 0) explodeAlpha -= 5;
else radius = 0;
explodeGreen-=4;
}