P5.js snippets

Making a square canvas

createCanvas(min(window.innerWidth,window.innerHeight), min(window.innerWidth,window.innerHeight));

Saving an image with a timestamp

function keyTyped() {
const d = new Date();
let stamp = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}_${d.getHours()}_${d.getMinutes()}_${d.getSeconds()}`
if (key === 's') {
save('project-name-' + stamp + '.png');
}
}

Grid of shapes

function grid() {
let numShapes = int(random(2,10));
let size = (8*width/10)/numShapes;
ellipseMode(CORNER);
rectMode(CORNER);
let randSpace = random(8,20);
for (y=0; y<numShapes; y++) {
for (x=0; x<numShapes; x++) {
push();
translate(width/10 + x*size, height/10 + y*size);
square(0,0,size - randSpace);
pop();
}
}
}