From 3354f25582d863d921082964509084d7992e00de Mon Sep 17 00:00:00 2001 From: zenoamaro Date: Wed, 26 Jun 2019 21:48:09 +0200 Subject: [PATCH] Circle drawing performance --- gfx.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gfx.js b/gfx.js index 8bf888f..c3cb4eb 100644 --- a/gfx.js +++ b/gfx.js @@ -60,11 +60,8 @@ export function strokeRect(ctx, x, y, w, h, color) { export function drawCircle(ctx, x, y, r, color) { for (let cy = -r; cy <= r; cy++) { - for (let cx = -r; cx <= r; cx++) { - if (cx*cx + cy*cy <= r*r + r*0.85) { - plot(ctx, x+cx, y+cy, color); - } - } + const w = Math.round(Math.sqrt(r*r - cy*cy)); + drawRect(ctx, x-w, y+cy, w*2, 1, color); } }