Skip to content

Instantly share code, notes, and snippets.

@jhafner
Created August 23, 2013 22:38
Show Gist options
  • Save jhafner/6324676 to your computer and use it in GitHub Desktop.
Save jhafner/6324676 to your computer and use it in GitHub Desktop.
Canvas (2D) Boilerplate
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
function loop() {
clear();
update();
draw();
queue();
}
function clear() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function update() {
// stub
}
function draw() {
// stub
}
function queue() {
window.requestAnimationFrame(loop);
}
loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment