From 4f205a13917bc93ac33c2a9cd688bebaaa796fd0 Mon Sep 17 00:00:00 2001 From: Daren Liang Date: Sat, 5 Dec 2020 17:43:10 -0500 Subject: [PATCH 1/2] Use faster canvas reset method --- code.js | 3 ++- page.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code.js b/code.js index cf2fcc3..96676b4 100644 --- a/code.js +++ b/code.js @@ -53,6 +53,7 @@ const circle = (ctx, type, color, radius, p) => { }); }; +// Not used currently const rect = (ctx, stroke, color, x, y, w, h) => { if (!stroke) { ctx.fillStyle = color; @@ -128,7 +129,7 @@ const main = () => { setTriangle(); } - rect(ctx, false, "white", 0, 0, canvas.width, canvas.height); + ctx.clearRect(0, 0, canvas.width, canvas.height); // Create point pairs beforehand const pointPairs = permute(points); diff --git a/page.html b/page.html index 03a4bff..c4e84f7 100644 --- a/page.html +++ b/page.html @@ -2,6 +2,6 @@ - + \ No newline at end of file From a179d10e910437ebf2de979f29126a8efecd6e20 Mon Sep 17 00:00:00 2001 From: Daren Liang Date: Sat, 5 Dec 2020 17:54:44 -0500 Subject: [PATCH 2/2] Wrap clearRect into a lambda --- code.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code.js b/code.js index 96676b4..73d3bb5 100644 --- a/code.js +++ b/code.js @@ -64,6 +64,10 @@ const rect = (ctx, stroke, color, x, y, w, h) => { } }; +const clearRect = (ctx, x, y, w, h) => { + ctx.clearRect(x, y, w, h); +}; + const text = (ctx, stroke, color, font, text, x, y) => { ctx.font = font; if (!stroke) { @@ -129,7 +133,7 @@ const main = () => { setTriangle(); } - ctx.clearRect(0, 0, canvas.width, canvas.height); + clearRect(ctx, 0, 0, canvas.width, canvas.height); // Create point pairs beforehand const pointPairs = permute(points);