Skip to content

Instantly share code, notes, and snippets.

@fffiloni
Created January 28, 2021 13:47
Show Gist options
  • Save fffiloni/3b1524dcfc9b327008165be66491c4e3 to your computer and use it in GitHub Desktop.
Save fffiloni/3b1524dcfc9b327008165be66491c4e3 to your computer and use it in GitHub Desktop.
Create canvas with container's dimension in p5js
// HTML index.html
// <div id="myCanvasContainer"></div>
// JS sketch.js
// Inside setup() function
let canvasDiv = document.getElementById('myCanvasContainer');
let width = canvasDiv.offsetWidth;
let height = canvasDiv.offsetHeight;
let sketchCanvas = createCanvas(width,height);
sketchCanvas.parent("myCanvasContainer");
sketchCanvas.id('myCanvas');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment