xxxxxxxxxx
54
/*
Inspired by Vera Molnár's Dispersion and simliar works
*/
//initiate setup function
let z = 0;
function setup() {
//make canvas scale to window size
createCanvas(windowWidth, windowHeight);
//don't fill any color in shapes
//noFill();
//outline set to black
stroke(255);
//outline width set to 2
frameRate(5);
}
//start draw loop
function draw() {
strokeWeight(random(20));
//set background color to white
background(0);
fill(noise(z+10)*255,noise(z+50)*255,noise(z+100)*255)
z++
//set column width to either canvas width or height divided by 20
let columnWidth = min(width / 20, height / 20);
//set row height to 1/3 of canvas
let rowHeight = height / 3;
//start for loop, define x, add columnWidth to x until it reaches canvas width
for (let x = 0; x < width; x+= columnWidth) {
//start for loop, define y, add columnWidth to y until it reaches canvas height
for (let y = 0; y < height; y+= rowHeight) {
//add 0 to 40 to y randomly
y += 20 + random(-20, 20);
//create rectangle with defined variables and scale column width 70% and row height 80%
rect(x, y, columnWidth * 0.7, rowHeight * 0.8);
}
}
//don't loop yet
//noLoop();
}
//function to run when mouse is pressed
function mousePressed() {
//loop again once when the mouse is pressed
loop();
}
//resize canvas to new window width and height when the window is resized
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}