I recently began exploring p5.js and I have a query regarding color randomization. Currently, it seems that the color only changes randomly when I restart the code. Is there a way to trigger this randomization every time the mouse is clicked?
Below is the code snippet I am working with:
let r, g, b;
function setup() {
createCanvas(400, 400);
r = random(255);
g = random(255);
b = random(255);
}
function draw() {
if (mouseIsPressed) {
fill(r,g,b);
} else {
fill(255);
}
ellipse(mouseX, mouseY, 80, 80);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>