Advertisement
xeromino

supershapes2

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