Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

rotrect

xeromino Jan 19th, 2016 122 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. int cols = 8, rows = cols, w, h, frms = 180;
  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);
  14.       i++;
  15.     }
  16.   }
  17. }
  18.  
  19. void draw() {
  20.   randomSeed(1234);
  21.   background(255);
  22.   v = new PVector(width/2+sin(theta)*270, height/2+cos(theta)*270);
  23.   for (int i=0; i<cols*rows; i++) {
  24.     squares[i].update();
  25.     squares[i].display();
  26.   }
  27.   theta += TWO_PI/frms;
  28.   if (frameCount<=frms) saveFrame("image-###.gif");
  29. }
  30.  
  31. class Square {
  32.  
  33.   PGraphics square;
  34.   float x, y;
  35.  
  36.   Square(float _x, float _y) {
  37.     x = _x;
  38.     y = _y;
  39.     square = createGraphics(w, h);
  40.   }
  41.  
  42.   void update() {
  43.     float sz = 200;
  44.     float distance = dist(v.x, v.y, x+w/2, y+h/2);
  45.     float r = map(distance, 0, sqrt(sq(width)+sq(height)), 0, TWO_PI*2);
  46.     float x = map(distance, 0, sqrt(sq(width)+sq(height)),0,60);
  47.     square.beginDraw();
  48.     //square.rectMode(CENTER);
  49.     square.background(255);
  50.     square.pushMatrix();
  51.     square.translate(w*.5, h*.5);
  52.     square.rotate(r);
  53.     square.noStroke();
  54.     square.fill(0);
  55.     square.rect(x, 0, sz, sz);
  56.     square.popMatrix();
  57.     square.endDraw();
  58.   }
  59.  
  60.   void display() {
  61.     image(square, x, y);
  62.   }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top