Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jbinkleyj/c9936e706d95d15ea9576a7134702484 to your computer and use it in GitHub Desktop.

Select an option

Save jbinkleyj/c9936e706d95d15ea9576a7134702484 to your computer and use it in GitHub Desktop.

Revisions

  1. @fffiloni fffiloni created this gist Jan 28, 2021.
    13 changes: 13 additions & 0 deletions canvas-fit-to-container-p5.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // 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');