Skip to content

Instantly share code, notes, and snippets.

@kuon
Last active April 19, 2016 00:08
Show Gist options
  • Save kuon/6c5af5362f911fc54d3c3b94c7713e5f to your computer and use it in GitHub Desktop.
Save kuon/6c5af5362f911fc54d3c3b94c7713e5f to your computer and use it in GitHub Desktop.
Basic logic demo of drawing
const ctx = canvas.getContext('2d')
const draw = () => {
drawObjects.forEach((obj: DrawObject) => {
obj.draw(ctx)
})
requestAnimationFrame(draw)
}
requestAnimationFrame(draw)
class DrawObject {
draw(ctx: CanvasRenderingContext2D) {
if (this.points.length < 2) {
return;
}
ctx.beginPath();
ctx.moveTo(this.points[0][0], this.points[0][1]);
this.points.forEach((point: number[], idx: number) {
if (idx === 0) {
return
}
ctx.lineTo(point[0], point[1])
})
ctx.stroke()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment