Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- color bg = #ffffff;
- color s = #000000;
- ArrayList bricks = new ArrayList();
- ArrayList bricks2 = new ArrayList();
- void setup() {
- size(400, 400);
- background(bg);
- stroke(s);
- strokeWeight(3);
- rectMode(CENTER);
- int y = 0;
- int h = 2;
- float w = 200;
- float theta = 0;
- while (y<height+50) {
- y += h;
- Brick brick = new Brick(y, h, theta, 300, 1);
- bricks.add(brick);
- Brick brick2 = new Brick(y, h, theta+PI/4, 250, 2);
- bricks2.add(brick2);
- h += 2;
- theta += TAU/25;
- }
- }
- void draw() {
- background(bg);
- for (int i=0; i<bricks.size();i++) {
- Brick brick = (Brick) bricks.get(i);
- brick.run();
- Brick brick2 = (Brick) bricks2.get(i);
- brick2.run();
- }
- //if (frameCount % 3 == 0 && frameCount<121) saveFrame("image-####.gif");
- }
- class Brick {
- float y, h, scalar, theta, w, cat;
- Brick(float _y, float _h, float _theta, float _w, float _cat) {
- y = _y;
- h = _h;
- w = _w;
- theta = _theta;
- cat = _cat;
- }
- void run() {
- move();
- display();
- }
- void move() {
- scalar = map(sin(theta*2), -1, 1, .5, 1.5);
- theta += 0.0523;
- }
- void display() {
- if (cat==1) {
- fill(0);
- }
- else {
- fill(255);
- }
- rect(width/2, y-h/2, ((w-5*h)*scalar), h);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement