xxxxxxxxxx
58
/*
Inspired by "rectangular forms" by the Belfort Group
Published in Computer Graphics and Art, 1976, Vol. 1, No. 3
*/
//define cellSize variable
let cellSize;
//initialize setup function
function setup() {
//set canvas to window width and height
createCanvas(windowWidth, windowHeight);
//no outline
noStroke();
frameRate(2);
}
//initiate draw loop
function draw() {
//set background to grey
background(127);
//set the cell size to either the width or height of the canvas / 10, whichever is smaller
cellSize = min(width / 100, height / 100);
//start for loop, define x and add cell size to x until x is more than width
for (let x = 0; x < width; x += cellSize) {
//start for loop, define y and add cell size to y until y is more than height
for (let y = 0; y < height; y += cellSize) {
//chance is equal to a number between 0 and 1.
let chance = random(0.6);
//if chance is less than 0.5 then fill the cell with white
if (chance < 0.5) {
fill(125,255,0);
//otherwise fill cell with black
} else {
fill(0,0,255);
}
//make square with variables
square(x, y, cellSize);
}
}
//don't loop yet
//noLoop();
}
//function for when mouse is pressed
function mousePressed() {
//rerun the cell generation pattern once when the mouse is pressed
loop();
}
//function to resize canvas if the window is resized
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}