Skip to content

Instantly share code, notes, and snippets.

@kublaj
Forked from jhafner/canvas-boilerplate.js
Created May 31, 2016 10:56
Show Gist options
  • Select an option

  • Save kublaj/8b49d7e6d0e0f5a09c06f9338de18e87 to your computer and use it in GitHub Desktop.

Select an option

Save kublaj/8b49d7e6d0e0f5a09c06f9338de18e87 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