Advertisement
xeromino

tic

Jun 30th, 2015
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. int edge, cols, rows, frames=120, radius=180;
  2. float cellSize, theta, offSet;
  3. PVector c;
  4.  
  5. void setup() {
  6.   size(540, 540, P2D);
  7.   smooth(4);
  8.   stroke(0);
  9.   edge = int(height*.1);
  10.   rows = 27;
  11.   cols = 27;
  12.   cellSize = (height-2*edge)/rows;
  13.   c = new PVector(cellSize, cellSize);
  14. }
  15.  
  16. void draw() {
  17.   randomSeed(4545);
  18.   background(255);
  19.   for (int j=0; j<cols; j++) {
  20.     float x = edge+(j+.5)*cellSize;
  21.     offSet = TWO_PI/cols*j;
  22.     for (int i=0; i<rows; i++) {
  23.       float offSet2 = TWO_PI/rows*i;
  24.       float s = map(sin(theta+offSet*3+offSet2*6), -1, 1, .1, .8);
  25.       float y = edge+(i+.5)*cellSize;
  26.       if (dist(x, y, width/2, height/2)<radius) {
  27.         if (random(1)>.3) {
  28.           cross(x, y, s);
  29.         } else {
  30.           ellipse(x, y, s*cellSize, s*cellSize);
  31.         }
  32.       }
  33.     }
  34.   }
  35.   theta -= TWO_PI/frames;
  36.   //if (frameCount<=frames) saveFrame("image-###.gif");
  37. }
  38.  
  39. void cross(float x, float y, float scalar) {
  40.   pushMatrix();
  41.   translate(x, y);
  42.   PVector temp = PVector.mult(c, scalar);
  43.   line(-temp.x/2, -temp.y/2, temp.x/2, temp.y/2);
  44.   line(-temp.x/2, temp.y/2, temp.x/2, -temp.y/2);
  45.   popMatrix();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement