Superformula

1.png
float n1 = 0;
float n2 = 0;
float n3 = 0;
float m = 0;

float rotY = 0;
float rotX = 0;

void setup() {
  size(1280, 720, P3D); 
  n1 = random(1,100);
  n2 = random(1,100);
  n3 = random(1,100);
  m = (int)random(2,10);
}

void draw() {
  background(255);
  translate(width/2, height/2);
  rotateY(rotY);
  rotateX(rotX);
  noStroke();
  lights();
  int total = 75;
  PVector[][] globe = new PVector[total+1][total+1];
  float r = 300;
  for (int i = 0; i < total+1; i++) {
    float lat = map(i, 0, total, -HALF_PI, HALF_PI);
    float r2 = superFormulaR(m, n1, n2, n3, lat);//superShape3D(lat, m, 0.2, 1.7, 1.7);
    //float r2 = supershape(lat, 2, 10, 10, 10);
    for (int j = 0; j < total+1; j++) {
      float lon = map(j, 0, total, -PI, PI);
      float r1 = superFormulaR(m, n1, n2, n3, lon);//supershape(lon, m, 0.2, 1.7, 1.7);
      //float r1 = supershape(lon, 8, 60, 100, 30);
      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);
  //noFill();
  //offset += 5;
  pushMatrix();
  colorMode(HSB);
  for (int i = 0; i < total; i++) {
    float hu = map(i, 0, total, 0, 255*6);
    fill((hu + 0) % 255 , (hu *10) % 255, (hu /2) % 255);
    beginShape(TRIANGLE_STRIP);
    for (int j = 0; j < total+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();
  }
  popMatrix();
    rotY += PConstants.TWO_PI / 1000;
    rotX += PConstants.TWO_PI / 1000;
    if (frameCount % 350 == 0) {
      n1 = random(1,100);
      n2 = random(1,100);
      n3 = random(1,100);
      m = (int)random(2,20);  
    }
}

public PVector superFormula3D(float m, float n1, float n2, float n3, float phi, float theta)
{
   float r1 = superFormulaR(m, n1, n2, n3, theta);
   float r2 = superFormulaR(m, n1, n2, n3, phi);
   return new PVector(r1 * cos(theta) * r2 * cos(phi), r1 * sin(theta) * r2 * cos(phi), r2 * sin(phi));
}

public float superFormulaR(float m, float n1, float n2, float n3, float phi)
{
   float t1,t2;
   float a=1,b=1;

   t1 = cos(m * phi / 4) / a;
   t1 = abs(t1);
   t1 = pow(t1,n2);

   t2 = sin(m * phi / 4) / b;
   t2 = abs(t2);
   t2 = pow(t2,n3);

   return 1/pow(t1+t2,-1/n1);
}



public PVector superFormula(float m, float n1, float n2, float n3, float phi)
{
   float r;
   float t1,t2;
   float a=1,b=1;

   t1 = cos(m * phi / 4) / a;
   t1 = abs(t1);
   t1 = pow(t1,n2);

   t2 = sin(m * phi / 4) / b;
   t2 = abs(t2);
   t2 = pow(t2,n3);

   r = pow(t1+t2,1/n1);
   if (abs(r) == 0) {
      return new PVector(0,0);
   } else {
      r = 1 / r;
      return new PVector(r * cos(phi),r * sin(phi));
   }
}

Wiki: here