Advertisement
xeromino

elton

Aug 14th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. void setup() {
  2.   size(800, 800); // Canvas size
  3.   rectMode(CORNER); // Jerome: not necessary, CORNER is the default for rectangles
  4.   noStroke(); // Jerome: this tells Processing not to draw lines or edges
  5.   noLoop(); // Jerome: so you really want the program to run only once?
  6.   frameRate(1); // Jerome: not necessary after having used noLoop() to have the sketch run only once
  7.   randomSeed(minute()+second()); // Jerome: not necessary either
  8. }
  9. void draw() {
  10.   background(120); // Clear the screen to grey
  11.   //25 squares
  12.   int num = 5; //select 25 squares each frame
  13.   int gap=(int) random(1, 20); //select a random gap between each square
  14.   //calculate the size of each square for the giving nomber of square and gap between them
  15.   float cellsize = ( width - (num + 1) * gap ) / (float)num;
  16.   //print out the size of each square
  17.   println("cellsize = " + cellsize);
  18.   //calculate shadows offset
  19.   float offsetX = cellsize/10.0 + (int) random (1, 2);
  20.   float offsetY = cellsize/10.0 + (int) random (1, 2);
  21.   for (int i=0; i<num; i++) {
  22.     for (int j=0; j<num; j++) {
  23.       fill(100, 100); //shadow color
  24.       rect(gap * (i+1) + cellsize * i + offsetX, gap * (j+1) + cellsize * j + offsetY, cellsize, cellsize);
  25.     } // Jerome: you had forgotten this one, you also need to close a previous { with a corresponding }
  26.   } // Jerome: you had forgotten this one, you also need to close a previous { with a corresponding }
  27. } // Jerome: you had forgotten this one, you also need to close a previous { with a corresponding }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement