p5js if mouse pressed code example
Example 1: p5 js if mouse pressed
if (mouseIsPressed)
Example 2: p5 js if mouse pressed
let cnv;
let d;
let g;
function setup() {
cnv = createCanvas(100, 100);
cnv.mousePressed(changeGray);
d = 10;
g = 100;
}
function draw() {
background(g);
ellipse(width / 2, height / 2, d, d);
}
function mousePressed() {
d = d + 10;
}
function changeGray() {
g = random(0, 255);
}
Example 3: if mousepressed javascript
var mouseDown = 0;
document.body.onmousedown = function() {
++mouseDown;
}
document.body.onmouseup = function() {
--mouseDown;
}