Created
June 14, 2019 17:01
-
-
Save crazytonyi/e19443c007de315df252fab741ad2132 to your computer and use it in GitHub Desktop.
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
class CheckerboardPainter { | |
paint(ctx, geom, properties) { | |
// Use `ctx` as if it was a normal canvas | |
const colors = ['red', 'green', 'blue']; | |
const size = 32; | |
for(let y = 0; y < geom.height/size; y++) { | |
for(let x = 0; x < geom.width/size; x++) { | |
const color = colors[(x + y) % colors.length]; | |
ctx.beginPath(); | |
ctx.fillStyle = color; | |
ctx.rect(x * size, y * size, size, size); | |
ctx.fill(); | |
} | |
} | |
} | |
} | |
// Register our class under a specific name | |
registerPaint('checkerboard', CheckerboardPainter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment