Created
May 23, 2018 08:28
-
-
Save max-lv/ea1d8ea779957da8451c368fa739af4b to your computer and use it in GitHub Desktop.
Collections of boilerplate code and util functions for codepen.io
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
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