Last active
October 28, 2016 01:15
-
-
Save lonelydatum/21f785c6399251ba0fb269c2f786e3f8 to your computer and use it in GitHub Desktop.
Makes checker. Pass in size of square
This file contains hidden or 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
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