From 782bc3e7bc6f13253fdab56552ed5a3d5290b54b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 10 May 2024 20:57:44 -0600 Subject: [PATCH] chore: randomColor util --- docs/js/app.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/js/app.js b/docs/js/app.js index fbcd098c..fc4a8745 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -19,6 +19,13 @@ const signaturePad = new SignaturePad(canvas, { backgroundColor: 'rgb(255, 255, 255)' }); +function randomColor() { + const r = Math.round(Math.random() * 255); + const g = Math.round(Math.random() * 255); + const b = Math.round(Math.random() * 255); + return `rgb(${r},${g},${b})`; +} + // Adjust canvas coordinate space taking into account pixel ratio, // to make it look crisp on mobile devices. // This also causes canvas to be cleared. @@ -121,24 +128,14 @@ redoButton.addEventListener("click", () => { }); changeBackgroundColorButton.addEventListener("click", () => { - const r = Math.round(Math.random() * 255); - const g = Math.round(Math.random() * 255); - const b = Math.round(Math.random() * 255); - const color = "rgb(" + r + "," + g + "," + b + ")"; - - signaturePad.backgroundColor = color; + signaturePad.backgroundColor = randomColor(); const data = signaturePad.toData(); signaturePad.clear(); signaturePad.fromData(data); }); changeColorButton.addEventListener("click", () => { - const r = Math.round(Math.random() * 255); - const g = Math.round(Math.random() * 255); - const b = Math.round(Math.random() * 255); - const color = "rgb(" + r + "," + g + "," + b + ")"; - - signaturePad.penColor = color; + signaturePad.penColor = randomColor(); }); changeWidthButton.addEventListener("click", () => {