Advertisement
xeromino

superEllipse

Aug 3rd, 2016
278
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float theta;
  2. float n = 0, a, b;
  3. int frms = 120, num = 25;
  4.  
  5. void setup() {
  6.   size(750, 540);
  7. }
  8.  
  9. void draw() {
  10.   background(51);
  11.  
  12.   translate(width/2, height/2);
  13.  
  14.   noFill();
  15.   stroke(238, 150);
  16.  
  17.   for (int i=0; i<num; i++) {
  18.     float offSet = PI/3/num*i;
  19.     n = map(sin(theta+offSet), -1, 1, 0.1, 3);
  20.     a = map(sin(theta), -1, 1, 100, 200);
  21.     b = a;
  22.     beginShape();
  23.     for (float angle = 0; angle<TWO_PI; angle+= 0.1) {
  24.       float na = 2/n;
  25.       float x = pow(abs(cos(angle+offSet)), na)*a*sgn(cos(angle));
  26.       float y = pow(abs(sin(angle+offSet)), na)*b*sgn(sin(angle));
  27.       vertex(x, y);
  28.     }
  29.     endShape(CLOSE);
  30.   }
  31.  
  32.   theta += TWO_PI/frms;
  33.   if (frameCount <= frms) saveFrame("image-###.gif");
  34. }
  35.  
  36. int sgn(float val) {
  37.   if (val>0) {
  38.     return 1;
  39.   } else if (val<0) {
  40.     return -1;
  41.   } else {
  42.     return 0;
  43.   }
  44. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement