Advertisement
xeromino

Barrel

Nov 8th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. ArrayList thingies = new ArrayList();
  2. float grid, sz, theta;
  3. int flip = -1;
  4. int stepx = 20;
  5. int stepy = stepx/5*3;
  6. int column, row;
  7. color bg = #555152 ;
  8. color f1 = #2E2633  ;
  9. color f2 = #99173C ;
  10.  
  11. void setup() {
  12.   size(500, 300);
  13.   background(bg);
  14.   stroke(bg);
  15.   column = width/stepx;
  16.   row = height/stepy;
  17.   sz = column -2;
  18.   rectMode(CENTER);
  19.  
  20.   for (int y=0; y<height; y+=row) {
  21.     flip *= -1;
  22.     for (int x=0; x<width;x+=column) {
  23.       Thingie thingie = new Thingie(x, y, flip, theta);
  24.       thingies.add(thingie);
  25.       flip *= -1;
  26.       theta += TWO_PI/stepx;
  27.     }
  28.   }
  29. }
  30.  
  31. void draw() {
  32.   background(bg);
  33.  
  34.   for (int i=0; i<thingies.size();i++) {
  35.     Thingie thing = (Thingie) thingies.get(i);
  36.     thing.display();
  37.   }
  38.  
  39.  
  40.   if (frameCount % 4 == 0 && frameCount < 121) saveFrame("image-####.gif");
  41. }
  42.  
  43.  
  44. class Thingie {
  45.   float edge, theta, theta2, x, y;
  46.   int flip;
  47.  
  48.   Thingie(float _x, float _y, int _flip, float _theta) {
  49.     x = _x;
  50.     y = _y;
  51.     flip = _flip;
  52.     theta = _theta;
  53.     theta2 = _theta;
  54.    
  55.   }
  56.  
  57.   void display() {
  58.     fill(#ECE3B7);
  59.     noStroke();
  60.     //stroke(bg);
  61.     edge = map(sin(theta), -1, 1, 0, .5*sz);
  62.  
  63.     if (flip == 1) {
  64.       fill(f1);
  65.     }
  66.     else {
  67.       fill(f2);
  68.     }
  69.  
  70.     pushMatrix();  
  71.     translate(x+column/2, y+column/2);
  72.     rotate(theta2);
  73.     rect(0, 0, sz, sz, edge);
  74.     popMatrix();
  75.     theta -= 0.0523;
  76.     theta2 -= (0.0523);
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement