Advertisement
xeromino

pinata

Dec 24th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. int numElem = 50;
  2. myArc[] myArcs = new myArc[numElem];
  3.  
  4. color bg = #202020;
  5. color[] palette = {
  6.   #F58F12, #0B9EE7, #4EA731, #F4D910, #F334E3
  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 % 2 == 0 & frameCount<241) saveFrame("image-####.gif");
  41.  
  42. }
  43.  
  44.  
  45. class myArc {
  46.   float start, end, theta, sw;
  47.   color s;
  48.  
  49.   myArc(color _s, float _start, float _end, float _theta) {
  50.     s = _s;
  51.     start = _start;
  52.     end = _end + radians(.3);
  53.     theta = _theta;
  54.   }
  55.  
  56.   void run() {
  57.     move();
  58.     display();
  59.   }
  60.  
  61.   void move() {
  62.     sw = map(sin(theta*7), -1, 1, 20, 100);
  63.     theta += 0.0523/2;
  64.   }
  65.  
  66.   void display() {
  67.     stroke(s);
  68.     strokeWeight(sw);
  69.     arc(org_x, org_y, diam, diam, start, end);
  70.   }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement