Last active
October 27, 2016 17:54
-
-
Save ecridge/3b9ef1d715285562bb9b0afcf976a3e9 to your computer and use it in GitHub Desktop.
p5.js sketch that fills parent element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* p5.js sketch that fills its parent element. | |
* On my phone on a train so I haven’t actually tested… | |
*/ | |
var container; | |
function setup() { | |
var canvas; | |
// E.g. for a `<div id="container-id"></div>`. | |
container = document.getElementById('container-id'); | |
canvas = createCanvas(container.offsetWidth, container.offsetHeight); | |
canvas.parent('container-id'); | |
// Other setup… | |
} | |
/** | |
* Called automatically when the window is resized. | |
*/ | |
function windowResized() { | |
resizeCanvas(container.offsetWidth, container.offsetHeight); | |
} | |
function draw() { | |
// Other code… | |
// May have to call `resizeCanvas()` periodically here if you have other | |
// things on your page which cause the container to change shape. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment