Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int cols = 27, rows = cols, w, h, frms = 60;
- Square[] squares = new Square[rows*cols];
- float theta;
- PVector v;
- void setup() {
- size(540, 540, P2D);
- w = 540/cols;
- h = 540/rows;
- int i=0;
- for (int x=0; x<rows; x++) {
- for (int y=0; y<cols; y++) {
- squares[i] = new Square(x*w, y*h, i);
- i++;
- }
- }
- frameRate(20);
- }
- void draw() {
- randomSeed(1234);
- background(255);
- v = new PVector(width/2+sin(theta)*270, height/2+cos(theta)*270);
- for (int i=0; i<cols*rows; i++) {
- squares[i].update();
- squares[i].display();
- }
- theta += TWO_PI/frms;
- //if (frameCount<=frms) saveFrame("image-###.gif");
- }
- class Square {
- PGraphics square;
- float x, y;
- int b, f, i;
- Square(float _x, float _y, int _i) {
- x = _x;
- y = _y;
- i = _i;
- square = createGraphics(w, h);
- }
- void update() {
- float sz = 120;
- float distance = dist(v.x, v.y, x+w/2, y+h/2);
- float r = map(distance, 0, sqrt(sq(width)+sq(height)), 0, TWO_PI*2);
- sz = map(distance, 0, sqrt(sq(width)+sq(height)), 20, 200);
- if (i%2==0) {
- b = 255;
- f = 0;
- } else {
- b = 0;
- f = 255;
- };
- square.beginDraw();
- square.background(b);
- square.pushMatrix();
- square.translate(w*.25, h*.5);
- square.rotate(r);
- square.noStroke();
- square.fill(f);
- square.rect(0, 0, sz, sz);
- square.popMatrix();
- square.endDraw();
- }
- void display() {
- image(square, x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement