Skip to content

Instantly share code, notes, and snippets.

@lonelydatum
Last active October 28, 2016 01:15
Show Gist options
  • Save lonelydatum/21f785c6399251ba0fb269c2f786e3f8 to your computer and use it in GitHub Desktop.
Save lonelydatum/21f785c6399251ba0fb269c2f786e3f8 to your computer and use it in GitHub Desktop.
Makes checker. Pass in size of square
function makeChecker(size=1) {
const black = '#000000'
const white = '#FFFFFF'
const w = canvas.width/size
const h = canvas.height/size
let yColor = black
// let yColor = white
for(let y=0; y<h; y++) {
yColor = (yColor===black) ? white : black
let prev = null
let curr = null
for(let x=0; x<w; x++) {
if(!curr) {
curr = yColor
}else{
prev = curr
curr = (prev===black) ? white : black
}
ctx.fillStyle = curr
ctx.fillRect(x*size, y*size, size, size);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment