Advertisement
xeromino

LeafDonut

Nov 12th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. color bg = #0D3F40;
  2. color f = #8FA671;
  3. color s = f;
  4. int steps = 40;
  5. int isteps = steps/2;
  6. float oRadius, iRadius, org_x, org_y, theta;
  7. Circle[] outerCircles = new Circle[steps];
  8. Circle[] innerCircles = new Circle[isteps];
  9.  
  10. void setup() {
  11.   size(500, 500);
  12.   background(bg);
  13.  
  14.   org_x = width/2;
  15.   org_y = height/2;
  16.   theta = 0;
  17.  
  18.   oRadius = width/3;
  19.   iRadius = width/6;
  20.  
  21.   for (int i=0; i < steps; i++) {
  22.     int dir = 1;
  23.     outerCircles[i] = new Circle(theta, dir, oRadius);
  24.     theta += TAU/steps;
  25.   }
  26.  
  27.   for (int i=0; i < isteps; i++) {
  28.     int dir = -1;
  29.     innerCircles[i] = new Circle(theta, dir, iRadius);
  30.     theta += TAU/isteps;
  31.   }
  32. }
  33.  
  34. void draw() {
  35.   background(bg);
  36.   for (int i=0; i<innerCircles.length; i++) {
  37.     innerCircles[i].run();
  38.   }
  39.  
  40.   for (int i=0; i<outerCircles.length; i++) {
  41.     outerCircles[i].run();
  42.   }
  43.  
  44.   fill(bg);
  45.   ellipse(org_x, org_y, 40,40);
  46.  
  47.   //if (frameCount % 1 == 0 && frameCount < 25) saveFrame("image-####.gif");
  48. }
  49.  
  50. class Circle {
  51.   float x, y, sz, theta, theta2, radius;
  52.   int dir;
  53.  
  54.   Circle(float _theta, int _dir, float _radius) {
  55.     theta = _theta;
  56.     dir = _dir;
  57.     radius = _radius;
  58.   }
  59.  
  60.   void run() {
  61.     move();
  62.     display();
  63.   }
  64.  
  65.  
  66.   void move() {
  67.     x = org_x + sin(theta)*radius;
  68.     y = org_y + cos(theta)*radius;  
  69.     theta += 0.0523/4*dir;
  70.   }
  71.  
  72.   void display() {
  73.  
  74.     switch(dir) {
  75.     case 1:
  76.       sz = 45;
  77.       fill(bg);
  78.       break;
  79.     case -1:
  80.       sz = 200;
  81.       //stroke(s);
  82.       noStroke();
  83.       fill(f,30);
  84.       break;
  85.     }
  86.     ellipse(x, y, sz, sz);
  87.   }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement