Created
June 11, 2021 13:06
-
-
Save amygoodchild/cc94a63978cbf4849cf53b192551c49d to your computer and use it in GitHub Desktop.
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
var resize = { | |
time: 0, | |
delay: 300, | |
handled: true | |
} | |
var circleDiameter; | |
function setup() { | |
let s = min(window.innerWidth, window.innerHeight); | |
createCanvas(s, s); | |
pixelDensity(1); | |
sizeSettings(); | |
} | |
function sizeSettings(){ | |
// handle different screensizes, runs when the screen resizes | |
// for example... | |
circleDiameter = width*0.8; | |
} | |
function draw() { | |
background(50,50,50); | |
ellipse(width/2, height/2, circleDiameter); | |
if (!resize.handled){ | |
// Check the last time the window resized so we dont constantly deal with it | |
// as someone is dragging the window size. | |
// Instead, it waits for a pause in resizing. | |
if (resize.time + resize.delay < millis()){ | |
handleResize(); | |
resize.handled = true; | |
} | |
} | |
} | |
// handle resizing and rejig appropriate variables | |
function handleResize(){ | |
let s = min(window.innerWidth, window.innerHeight); | |
resizeCanvas(s, s); | |
sizeSettings(); | |
} | |
// Event called whenever the browser window is resized | |
function myResize() { | |
resize.time = millis(); | |
resize.handled = false; | |
} | |
window.addEventListener('resize', myResize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment