Advertisement
xeromino

rattlesnake

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