Skip to content

Instantly share code, notes, and snippets.

@crazytonyi
Created June 14, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazytonyi/e19443c007de315df252fab741ad2132 to your computer and use it in GitHub Desktop.
Save crazytonyi/e19443c007de315df252fab741ad2132 to your computer and use it in GitHub Desktop.
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