I am quite new to p5 and am struggling to achieve multiple canvases on a single webpage. I can manage to to get two running, using two instance functions, but I can’t figure out how to position them off their default position. Is there a way to do this from in the sketch itself or is it better to use the html file?
Ideally, I want to have 8 sketches, whose size and positioning is based on the width of the display, and ideally only run fully when they are visible on the page (i.e. as you scroll down the page). I’ve looked for similar examples, but cannot seem to find any, so any advice about the best way to achieve this would be really appreciated!
In my blog math-os.com, some posts include multiple P5 sketches. For instance :
I guess that more and more sketches in a single post consume more and more ressources. Does anyone know how to “activate” a sketch only if it is visible ? Or only if one explicitly asks for it to be active (by pressing a button) ?
'use strict';
function setup() {
createCanvas(500, 400);
noLoop();
}
Or if you have a sketch which only needs to update the canvas after a user input such as moving the mouse, besides using noLoop() you also call redraw() within the user input event callback: