Simple Function Example
// Random with a function
 
void setup() {
  size (200, 400);
  background(0);
  noStroke();
  smooth();
  noLoop();
}
 
void draw() {
  for (int i = 0; i < width; i+= 10) {
    for (int j = 0; j < height / 2; j+= 10) {
      drawSquare(i, j, 10);
    }
  }
  for (int i = 0; i < width; i+= 7) {
    for (int j = 0; j < height / 2; j+= 7) {
      drawSquare(i, j + height / 2, 5);
    }
  }
}
 
void drawSquare(int x, int y, int squareSize) {
  fill (random(0,255));
  rect (x, y, squareSize, squareSize);
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License