xxxxxxxxxx
65
/*
Inspired by George Nees' Micro-Innovation Series (1966)
*/
//define x, y, w, h variables
let x;
let y;
let w;
let h;
//setup function declaration
function setup() {
//set canvas size to scale with the window’s width and height
createCanvas(windowWidth, windowHeight);
console.log(windowWidth);
console.log(windowHeight);
//set rectangles to create from their center point instead of top left corner
rectMode(CENTER);
//don’t fill any color
noFill();
//outline white
stroke(255);
//outline width 2
strokeWeight(2);
}
//draw loop function initialization
function draw() {
//set background to black
background(0);
//for loop initialization, i starts at 0, add one each time until it reaches 400
for (let i = 0; i < 400; i++) {
// if statement declaration. if a random number between 0-10 is less than 8 then run
if (random(10) < 8) {
//width = a random number between 5-25
w = random(5, 25);
console.log(w);
//height = a random number between 50-150
h = random(50, 150);
console.log(h);
//if the number is greater than 7
} else {
//w = a random number between 50-150
w = random(50, 150);
console.log(w);
//h = a random number between 5-25
h = random(5, 25);
console.log(h);
}
//set x to a random number between w and window width - at least 5
x = random(w, width - w);
console.log(x);
//set y to a random number between h and window height - at least 5
y = random(h, height - h);
console.log(y);
//create a rectangle with the previous random variables for x,y positions and its width and height
rect(x, y, w, h);
}
//don’t loop the program by default - only run once
noLoop();
}
//when the mouse is pressed loop the program to run again.
function mousePressed() {
loop();
}