Skip to content

Instantly share code, notes, and snippets.

@jseakle
Created June 13, 2013 08:47
Show Gist options
  • Save jseakle/5772208 to your computer and use it in GitHub Desktop.
Save jseakle/5772208 to your computer and use it in GitHub Desktop.
int width = 200;
int height = 200;
int numsquares = width / 20;
Square[][] squares = new Square[numsquares][numsquares];
void setup() {
for(int i = 0; i < squares.length; i++) {
for(int j = 0; j < squares[0].length; j++) {
squares[i][j] = new Square();
}
}
background(255);
size(width + 1, height + 1);
}
void draw() {
for(int i = 0; i < squares.length; i++) {
for(int j = 0; j < squares[0].length; j++) {
if(squares[i][j] != null) {
squares[i][j].display();
}
}
}
}
class Square {
int x;
int y;
color c;
Square() {
x = (int) random(numsquares);
y = (int) random(numsquares);
c = color(255,0,0);
}
void display() {
fill(c);
noStroke();
rect(x * (width / numsquares) + 1,
y * (height / numsquares) + 1,
width / numsquares - 1,
height / numsquares - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment