Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. float scaler = 200;
  2. int m = 2;
  3. float n1 = 18;
  4. float n2 = 1;
  5. float n3 = 1;
  6.  
  7. void setup() {
  8.   size(700, 700);
  9.   smooth();
  10.   noFill();
  11.   stroke(255);
  12. }
  13.  
  14. void draw() {
  15.   background(0);
  16.  
  17.   pushMatrix();
  18.   translate(width/2, height/2);
  19.  
  20.   float newscaler = scaler;
  21.   for (int s = 16; s > 0; s--) {  
  22.     beginShape();
  23.  
  24.     float mm = m + s;
  25.     float nn1 = n1 + s;
  26.     float nn2 = n2 + s;
  27.     float nn3 = n3 + s;
  28.     newscaler = newscaler * 0.98;
  29.     float sscaler = newscaler;
  30.  
  31.     PVector[] points = superformula(mm, nn1, nn2, nn3);
  32.     curveVertex(points[points.length-1].x * sscaler, points[points.length-1].y * sscaler);
  33.     for (int i = 0;i < points.length; i++) {
  34.       curveVertex(points[i].x * sscaler, points[i].y * sscaler);
  35.     }
  36.     curveVertex(points[0].x * sscaler, points[0].y * sscaler);
  37.     endShape();
  38.   }
  39.   popMatrix();
  40. }
  41.  
  42.  
  43. PVector[] superformula(float m,float n1,float n2,float n3) {
  44.   int numPoints = 360;
  45.   float phi = TWO_PI / numPoints;
  46.   PVector[] points = new PVector[numPoints+1];
  47.   for (int i = 0;i <= numPoints;i++) {
  48.     points[i] = superformulaPoint(m,n1,n2,n3,phi * i);
  49.   }
  50.   return points;
  51. }
  52.  
  53. PVector superformulaPoint(float m,float n1,float n2,float n3,float phi) {
  54.   float r;
  55.   float t1,t2;
  56.   float a=1,b=1;
  57.   float x = 0;
  58.   float y = 0;
  59.  
  60.   t1 = cos(m * phi / 4) / a;
  61.   t1 = abs(t1);
  62.   t1 = pow(t1,n2);
  63.  
  64.   t2 = sin(m * phi / 4) / b;
  65.   t2 = abs(t2);
  66.   t2 = pow(t2,n3);
  67.  
  68.   r = pow(t1+t2,1/n1);
  69.   if (abs(r) == 0) {
  70.     x = 0;
  71.     y = 0;
  72.   }  
  73.   else {
  74.     r = 1 / r;
  75.     x = r * cos(phi);
  76.     y = r * sin(phi);
  77.   }
  78.  
  79.   return new PVector(x, y);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement