xxxxxxxxxx
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Exercise 6-8: Create a grid of squares (each colored randomly)
// using a for loop.
// (Hint: You will need two for loops!) Recode the same pattern
// using a "while" loop instead of "for."
int c = (int) random(0,1000);
void setup(){
fullScreen();
frameRate(4);
// With a for loop
for (int x = 0; x < width; x+=10) {
for (int y = 0; y < height; y+=10) {
noStroke();
fill(random(c),random(c),random(c));
rect(x, y, 10, 10);
}}
}
void draw(){
// With a while loop
frameRate(4);
int x = 0;
while (x < width) {
int y = 0;
while (y < height) {
noStroke();
fill(random(c),random(c),random(c));
ellipse(x, y, 20, 20);
y += 10;
}
x += 10;
}}