1let cnv;
2let d;
3let g;
4function setup() {
5 cnv = createCanvas(100, 100);
6 cnv.mousePressed(changeGray); // attach listener for
7 // canvas click only
8 d = 10;
9 g = 100;
10}
11
12function draw() {
13 background(g);
14 ellipse(width / 2, height / 2, d, d);
15}
16
17// this function fires with any click anywhere
18function mousePressed() {
19 d = d + 10;
20}
21
22// this function fires only when cnv is clicked
23function changeGray() {
24 g = random(0, 255);
25}