Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int cols = 8, rows = cols, w, h, frms = 180;
- 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++;
- }
- }
- }
- 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;
- Square(float _x, float _y) {
- x = _x;
- y = _y;
- square = createGraphics(w, h);
- }
- void update() {
- float sz = 200;
- 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);
- float x = map(distance, 0, sqrt(sq(width)+sq(height)),0,60);
- square.beginDraw();
- //square.rectMode(CENTER);
- square.background(255);
- square.pushMatrix();
- square.translate(w*.5, h*.5);
- square.rotate(r);
- square.noStroke();
- square.fill(0);
- square.rect(x, 0, sz, sz);
- square.popMatrix();
- square.endDraw();
- }
- void display() {
- image(square, x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement