Advertisement
xeromino

untitled

Dec 14th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. color bg = #ffffff;
  2. color s = #000000;
  3. ArrayList bricks = new ArrayList();
  4. ArrayList bricks2 = new ArrayList();
  5.  
  6. void setup() {
  7.  
  8.   size(400, 400);
  9.   background(bg);
  10.   stroke(s);
  11.   strokeWeight(3);
  12.  
  13.   rectMode(CENTER);
  14.  
  15.   int y = 0;
  16.   int h = 2;
  17.   float w = 200;
  18.   float theta = 0;
  19.  
  20.   while (y<height+50) {
  21.     y += h;
  22.     Brick brick = new Brick(y, h, theta, 300, 1);
  23.     bricks.add(brick);
  24.     Brick brick2 = new Brick(y, h, theta+PI/4, 250, 2);
  25.     bricks2.add(brick2);
  26.     h += 2;
  27.     theta += TAU/25;
  28.   }
  29. }
  30.  
  31. void draw() {
  32. background(bg);
  33.   for (int i=0; i<bricks.size();i++) {
  34.     Brick brick = (Brick) bricks.get(i);
  35.     brick.run();
  36.     Brick brick2 = (Brick) bricks2.get(i);
  37.     brick2.run();
  38.   }
  39.  
  40.   //if (frameCount % 3 == 0 && frameCount<121) saveFrame("image-####.gif");
  41. }
  42. class Brick {
  43.   float y, h, scalar, theta, w, cat;
  44.  
  45.   Brick(float _y, float _h, float _theta, float _w, float _cat) {
  46.     y = _y;
  47.     h = _h;
  48.     w = _w;
  49.     theta = _theta;
  50.     cat = _cat;
  51.   }
  52.  
  53.   void run() {
  54.     move();
  55.     display();
  56.   }
  57.  
  58.  
  59.   void move() {
  60.     scalar = map(sin(theta*2), -1, 1, .5, 1.5);
  61.     theta += 0.0523;
  62.   }
  63.  
  64.  
  65.   void display() {
  66.     if (cat==1) {
  67.       fill(0);
  68.     }
  69.     else {
  70.       fill(255);
  71.     }    
  72.     rect(width/2, y-h/2, ((w-5*h)*scalar), h);
  73.   }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement