P5.js snippets

Categories

Published:

Updated March 6, 2022

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('-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