Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int cols = 12, rows = cols, w, h, frms = 120;
- 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=1; x<(rows-1); x++) {
- for (int y=1; y<(cols-1); y++) {
- squares[i] = new Square(x*w, y*h);
- i++;
- }
- }
- }
- void draw() {
- background(0);
- v = new PVector(width/2+sin(theta)*width/2, height/2+cos(theta)*height/2);
- for (int i=0; i<(cols-2)*(rows-2); i++) {
- println(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 distance = dist(v.x, v.y, x+w/2, y+h/2);
- float r = map(distance, 0, sqrt(sq(width)+sq(height)), 0, HALF_PI);
- float x = map(distance, 0, sqrt(sq(width)+sq(height)), -30, 30);
- float sz = map(distance, 0, sqrt(sq(width)+sq(height)), w*.9, w*1.2);
- square.beginDraw();
- square.rectMode(CENTER);
- square.background(0);
- square.pushMatrix();
- square.translate(w/2, h/2);
- square.rotate(r);
- square.fill(0);
- square.stroke(255);
- square.ellipse(x, 0, sz, sz);
- square.ellipse(x, x/2, sz/2, sz/2);
- square.popMatrix();
- square.endDraw();
- }
- void display() {
- image(square, x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement