I am currently using this video tutorial:
to generate super shapes. I've checked my code over and over but still can't get it to generate the shapes outlined by the guide: http://paulbourke.net/geometry/supershape/ . I am struggling to see the flaw in my code as it looks identical to the tutorial? Any help is welcome. Thank you :)
import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam cam;
PVector[][] globe;
int sum = 75;
void setup() {
size(1900, 950, P3D);
cam = new PeasyCam(this, 750);
globe = new PVector[sum+1][sum+1];
}
float a = 1;
float b = 1;
float supershape(float theta, float m, float n1, float n2, float n3) {
float t1 = abs((1/a)*cos(m*theta/4));
t1 = pow(t1, n2);
float t2 = abs((1/b)*sin(m*theta/4));
t2 = pow(t2, n3);
float t3 = t1 + t2;
float r = pow(t3, -1/n1);
return r;
}
void draw() {
background(0);
noStroke();
lights();
float r = 200;
for (int i=0; i<sum+1; i++) {
float lat = map(i, 0, sum, -HALF_PI, HALF_PI);
float r2 = supershape(lat,
8,
60,
100,
30);
for (int j=0; j<sum+1; j++) {
float lon = map(j, 0, sum, -PI, PI);
float r1 = supershape(lon,
2,
10,
10,
10);
float x = r*r1*cos(lon)*r2*cos(lat);
float y = r*r1*sin(lon)*r2*cos(lat);
float z = r*r2*sin(lat);
globe[i][j] = new PVector(x, y, z);
}
}
stroke(255);
fill(255);
for (int i=0; i<sum; i++) {
//ADD COLOUR HERE
beginShape(TRIANGLE_STRIP);
for (int j=0; j<sum+1; j++) {
PVector v1 = globe[i][j];
vertex(v1.x, v1.y, v1.z);
PVector v2 = globe[i+1][j];
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
}