Skip to content

Instantly share code, notes, and snippets.

@max-lv
Created May 23, 2018 08:28
Show Gist options
  • Save max-lv/ea1d8ea779957da8451c368fa739af4b to your computer and use it in GitHub Desktop.
Save max-lv/ea1d8ea779957da8451c368fa739af4b to your computer and use it in GitHub Desktop.
Collections of boilerplate code and util functions for codepen.io
let SCALE = 1;
let ctx = undefined;
function canvas (width, height) {
width = width ? width : 200;
height = height ? height : 200;
let body = document.querySelector("body");
body.innerHTML =
'<canvas ' +
'id="cvs" ' +
'width="' + width + 'px" ' +
'height="' + height + 'px">' +
'</canvas>';
ctx = cvs.getContext('2d');
return ctx;
}
function pixel (x, y, color) {
color = color ? color : "#aaa";
ctx.fillStyle = color;
ctx.fillRect(SCALE*x, SCALE*y, SCALE, SCALE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment