Advertisement
xeromino

beardedCircle

Nov 12th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. color bg = #ffffff;
  2. color f = #000000;
  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<outerCircles.length; i++) {
  37.     outerCircles[i].run();
  38.   }
  39.     for (int i=0; i<innerCircles.length; i++) {
  40.     innerCircles[i].run();
  41.   }
  42.  
  43.   if (frameCount % 1 == 0 && frameCount < 61) saveFrame("image-####.gif");
  44.  
  45. }
  46.  
  47. class Circle {
  48.   float x, y, sz, theta, theta2, radius;
  49.   int dir;
  50.  
  51.   Circle(float _theta, int _dir, float _radius) {
  52.     theta = _theta;
  53.     dir = _dir;
  54.     radius = _radius;
  55.     //sz = 20;
  56.   }
  57.  
  58.   void run() {
  59.     move();
  60.     display();
  61.   }
  62.  
  63.  
  64.   void move() {
  65.     x = org_x + sin(theta)*radius;
  66.     y = org_y + cos(theta)*radius;  
  67.     theta += 0.0523/4*dir;
  68.   }
  69.  
  70.   void display() {
  71.  
  72.     switch(dir) {
  73.     case 1:
  74.       sz=map(cos(theta), -1, 1, 20, 50);
  75.       stroke(s);
  76.       //noFill();
  77.       fill(f);
  78.       break;
  79.     case -1:
  80.       sz = 45;
  81.       stroke(s);
  82.       //noStroke();
  83.       fill(f);
  84.       break;
  85.     }
  86.  
  87.     ellipse(x, y, sz, sz);
  88.   }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement