Skip to content

Commit

Permalink
chore: randomColor util
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 11, 2024
1 parent 4b2947a commit 782bc3e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions docs/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit 782bc3e

Please sign in to comment.