Advertisement
xeromino

squares

Dec 31st, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. Square[] squares;
  2. int elem, unit;
  3. color f;
  4.  
  5. void setup() {
  6.   size(500, 500);
  7.   background(255);
  8.  
  9.   int counter=0;
  10.   int i=0;
  11.   int div = 4;
  12.   unit = width/div;
  13.   elem = int(sq(div));
  14.   squares = new Square[elem];
  15.  
  16.   for (int x = unit/2; x<width; x +=unit) {
  17.     counter = 0;
  18.     for (int y = unit/2; y<height; y +=unit) {
  19.  
  20.       squares[i] = new Square(float(x), float(y), counter);
  21.       i++;
  22.       counter++;
  23.     }
  24.   }
  25. }
  26.  
  27. void draw() {
  28.   background(255);
  29.   for (int i=0; i<elem; i++) {
  30.     squares[i].display();
  31.   }
  32.  
  33.     if (frameCount % 2 == 0 & frameCount<121) saveFrame("image-####.gif");
  34.  
  35. }
  36. class Square {
  37.   float x, y, theta,f;
  38.   float x1, x2, x3, x4, y1, y2, y3, y4;
  39.   float nx1, nx2, nx3, nx4, ny1, ny2, ny3, ny4;
  40.   float sz = unit*.3;
  41.   PVector pv;
  42.   int c;
  43.  
  44.   Square(float _x, float _y, int _counter) {
  45.     x = _x;
  46.     y = _y;
  47.     c = _counter;
  48.     x1 = x-sz;
  49.     y1 = y-sz;
  50.     x2 = x;
  51.     y2 = y-sz;
  52.     x3 = x-sz;
  53.     y3 = y;
  54.     x4 = x;
  55.     y4 = y;
  56.  
  57.     pv = new PVector(unit/2-sz, unit/2-sz);
  58.   }
  59.  
  60.   void display() {
  61.  
  62.     nx1 = map(sin(theta), -1, 1, x1-pv.x, x1);
  63.     ny1 = map(sin(theta), -1, 1, y1-pv.y, y1);
  64.     nx2 = map(sin(theta), -1, 1, x2+pv.x,x2);
  65.     ny2 = map(sin(theta), -1, 1, y2-pv.y,y2);
  66.     nx3 = map(sin(theta), -1, 1, x3-pv.x, x3);
  67.     ny3 = map(sin(theta), -1, 1, y3+pv.y, y3);
  68.     nx4 = map(sin(theta), -1, 1, x4+pv.x, x4);
  69.     ny4 = map(sin(theta), -1, 1, y4+pv.y, y4);
  70.     f = map(sin(theta),-1,1,100,180);
  71.  
  72.     fill(f);
  73.     stroke(f);
  74.     strokeWeight(5);
  75.     rect(nx1, ny1, sz, sz);
  76.     rect(nx2, ny2, sz, sz);
  77.     rect(nx3, ny3, sz, sz);
  78.     rect(nx4, ny4, sz, sz);
  79.  
  80.     theta += 0.0523;
  81.   }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement