Advertisement
xeromino

axidraw

Feb 20th, 2017
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import processing.pdf.*;
  2.  
  3. float theta;
  4. float n = 0, a, b;
  5. int frms = 60, num = 25;
  6. int counter = 100;
  7.  
  8. void setup() {
  9.   size(750, 540);
  10. }
  11.  
  12. void draw() {
  13.   background(255);
  14.   drawSuper();
  15. }
  16.  
  17. void drawSuper() {
  18.   translate(width/2, height/2);
  19.   noFill();
  20.   stroke(0);
  21.   for (int i=0; i<num; i++) {
  22.     float offSet = PI/4/num*i;
  23.     n = map(sin(theta+offSet), -1, 1, 0.1, 3);
  24.     a = map(sin(theta+offSet*3), -1, 1, 100, 200);
  25.     b = a;
  26.     beginShape();
  27.     for (float angle = 0; angle<TWO_PI; angle+= 0.05) {
  28.       float na = 2/n;
  29.       float x = pow(abs(cos(angle+offSet*2)), na)*a*sgn(cos(angle+offSet*0));
  30.       float y = pow(abs(sin(angle+offSet)), na)*b*sgn(sin(angle+offSet*3));
  31.       vertex(x, y);
  32.     }
  33.     endShape(CLOSE);
  34.   }
  35. }
  36.  
  37. int sgn(float val) {
  38.   if (val>0) {
  39.     return 1;
  40.   } else if (val<0) {
  41.     return -1;
  42.   } else {
  43.     return 0;
  44.   }
  45. }
  46.  
  47. void keyPressed() {
  48.   if (key == CODED) {
  49.     if (keyCode == UP) {
  50.       theta += TWO_PI/frms;
  51.     } else if (keyCode == DOWN) {
  52.       theta -= TWO_PI/frms;
  53.     }
  54.   }
  55.   if (key == 's') {
  56.     background(255);
  57.     beginRecord(PDF, int(random(99999)) + ".pdf");
  58.     drawSuper();
  59.     endRecord();
  60.     counter++;
  61.   }
  62. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement