Advertisement
xeromino

wobble

Dec 2nd, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. int numElem = 30;
  2. myArc[] myArcs = new myArc[numElem];
  3.  
  4. color bg = #000000;
  5. color[] palette = {
  6.   #322536, #8D2B38, #E53448, #FC6C63, #EFD79B
  7. };
  8. float org_x, org_y, diam;
  9.  
  10. void setup() {
  11.   size(500, 500);
  12.   background(bg);
  13.   noFill();
  14.  
  15.   strokeCap(SQUARE);
  16.  
  17.   org_x = width/2;
  18.   org_y = height/2;
  19.   diam = width*.6;
  20.   float end = 0;
  21.   float start = 0;
  22.   float theta = 0;
  23.  
  24.   for (int i=0; i<numElem; i++) {
  25.     color s = palette[i% palette.length ];  
  26.     start = end;
  27.     end = start + TAU/numElem;
  28.     myArcs[i]= new myArc(s, start, end, theta);
  29.     theta += TAU/numElem;
  30.   }
  31. }
  32.  
  33.  
  34. void draw() {
  35.   background(bg);
  36.   for (int i=0; i<numElem; i++) {
  37.     myArcs[i].run();
  38.   }
  39.  
  40.   if (frameCount % 4 == 0 & frameCount<241) saveFrame("image-####.gif");
  41.  
  42. }
  43.  
  44. class myArc {
  45.   float start, end, theta, sw;
  46.   color s;
  47.  
  48.   myArc(color _s, float _start, float _end, float _theta) {
  49.     s = _s;
  50.     start = _start;
  51.     end = _end + radians(.3);
  52.     theta = _theta;
  53.   }
  54.  
  55.   void run() {
  56.     move();
  57.     display();
  58.   }
  59.  
  60.   void move() {
  61.     sw = map(sin(theta*3), -1, 1, 20, 100);
  62.     theta += 0.0523/2;
  63.   }
  64.  
  65.   void display() {
  66.     stroke(s);
  67.     strokeWeight(sw);
  68.     arc(org_x, org_y, diam, diam, start, end);
  69.   }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement