Advertisement
xeromino

carpet

Jan 18th, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 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.   float div = 20;
  12.   float theta=0;
  13.   unit = int(width/div);
  14.   elem = int(sq(div-2));
  15.   squares = new Square[elem];
  16.  
  17.   for (int y = unit; y<height-unit; y +=unit) {
  18.     for (int x = unit; x<width-unit; x +=unit) {
  19.       squares[i] = new Square(float(x), float(y), theta, random(3));
  20.       i++;
  21.       theta += TAU/elem;
  22.     }
  23.   }
  24. }
  25.  
  26. void draw() {
  27.   background(#202020);
  28.   for (int i=0; i<squares.length; i++) {
  29.     squares[i].display();
  30.   }
  31.  
  32.   if (frameCount % 3 == 0 & frameCount<121) saveFrame("image-####.gif");
  33. }
  34. class Square {
  35.   float x, y, w, h, r, theta;
  36.  
  37.   Square(float _x, float _y, float _theta, float _r) {
  38.     x = _x;
  39.     y = _y;
  40.     h = unit;
  41.     theta = _theta;
  42.     r = _r;
  43.   }
  44.  
  45.   void display() {
  46.  
  47.     w = map(sin(theta), -1, 1, 5, unit-5);
  48.     if (r<2.5) {
  49.       stroke(#777777);
  50.       noFill();
  51.     }
  52.     else {
  53.       fill(#FCD300);
  54.       noStroke();
  55.     }
  56.  
  57.     //noFill();
  58.     rect(x, y, w, w,0);
  59.  
  60.     theta -= 0.0523;
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement