p5 js if mouse pressed

Solutions on MaxInterview for p5 js if mouse pressed by the best coders in the world

showing results for - "p5 js if mouse pressed"
Mathilda
09 Oct 2016
1if (mouseIsPressed)
Janna
31 Nov 2018
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}