Advertisement
xeromino

superShape

Aug 4th, 2016
320
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float theta;
  2. int frms = 120, num = 50;
  3. float n1, n2, n3, m, a, b;
  4.  
  5. void setup() {
  6.   size(750, 540, P2D);
  7.   smooth(8);
  8.   n1 = 1;
  9.   n2 = 1;
  10.   n3 = 1;
  11.   m = 5;
  12.   a = 1;
  13.   b = 1;
  14. }
  15.  
  16. void draw() {
  17.   background(51);
  18.   translate(width/2, height/2);
  19.   pushMatrix();
  20.   rotate(PI/2);
  21.   noFill();
  22.   stroke(238, 120);
  23.   m = 7; //(int) map(mouseX, 0, width, 0, 7);
  24.   n1 = map(sin(theta), -1, 1, 0.1, 1); //map(mouseY, 0, height, 0, 1);
  25.   n2 = n3 = n1;
  26.  
  27.   //println("m: " + m + "n1: " + n1);
  28.  
  29.   for (int i=0; i<num; i++) {
  30.     float offSet = PI/2/num*i;
  31.     float radius = 200;
  32.     int total = 250;
  33.     float incr = TWO_PI/total;
  34.     beginShape();
  35.     for (float angle = 0; angle<TWO_PI; angle+=incr) {
  36.       float r = supershape(angle);
  37.       float x = radius * r * cos(angle+offSet);
  38.       float y = radius * r * sin(angle+offSet);
  39.       vertex(x, y);
  40.     }
  41.     endShape(CLOSE);
  42.   }
  43.   popMatrix();
  44.  
  45.   theta += TWO_PI/frms;
  46.   //if (frameCount <= frms) saveFrame(m + "_image-###.gif");
  47. }
  48.  
  49. float supershape(float theta) {
  50.   float part1 = (1/a)*cos(theta*m/4);
  51.   part1 = abs(part1);
  52.   part1 = pow(part1, n2);
  53.  
  54.   float part2 = (1/b)*sin(theta*m/4);
  55.   part2 = abs(part2);
  56.   part2 = pow(part2, n3);
  57.  
  58.   float part3 = pow(part1 + part2, 1/n1);
  59.  
  60.   //if (part3==0) return 0;
  61.  
  62.   return 1/part3;
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement