Advertisement
xeromino

acid

Jan 19th, 2016
297
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int cols = 27, rows = cols, w, h, frms = 60;
  2. Square[] squares = new Square[rows*cols];
  3. float theta;
  4. PVector v;
  5.  
  6. void setup() {
  7.   size(540, 540, P2D);
  8.   w = 540/cols;
  9.   h = 540/rows;
  10.   int i=0;
  11.   for (int x=0; x<rows; x++) {
  12.     for (int y=0; y<cols; y++) {
  13.       squares[i] = new Square(x*w, y*h, i);
  14.       i++;
  15.     }
  16.   }
  17.   frameRate(20);
  18. }
  19.  
  20. void draw() {
  21.   randomSeed(1234);
  22.   background(255);
  23.   v = new PVector(width/2+sin(theta)*270, height/2+cos(theta)*270);
  24.   for (int i=0; i<cols*rows; i++) {
  25.     squares[i].update();
  26.     squares[i].display();
  27.   }
  28.   theta += TWO_PI/frms;
  29.   //if (frameCount<=frms) saveFrame("image-###.gif");
  30. }
  31.  
  32. class Square {
  33.  
  34.   PGraphics square;
  35.   float x, y;
  36.   int b, f, i;
  37.  
  38.   Square(float _x, float _y, int _i) {
  39.     x = _x;
  40.     y = _y;
  41.     i = _i;
  42.     square = createGraphics(w, h);
  43.   }
  44.  
  45.   void update() {
  46.     float sz = 120;
  47.     float distance = dist(v.x, v.y, x+w/2, y+h/2);
  48.     float r = map(distance, 0, sqrt(sq(width)+sq(height)), 0, TWO_PI*2);
  49.     sz = map(distance, 0, sqrt(sq(width)+sq(height)), 20, 200);
  50.     if (i%2==0) {
  51.       b = 255;
  52.       f = 0;
  53.     } else {
  54.       b = 0;
  55.       f = 255;
  56.     };
  57.     square.beginDraw();
  58.     square.background(b);
  59.     square.pushMatrix();
  60.     square.translate(w*.25, h*.5);
  61.     square.rotate(r);
  62.     square.noStroke();
  63.     square.fill(f);
  64.     square.rect(0, 0, sz, sz);
  65.     square.popMatrix();
  66.     square.endDraw();
  67.   }
  68.  
  69.   void display() {
  70.     image(square, x, y);
  71.   }
  72. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement