Answers for "p5 on mouse press"

0

p5 js if mouse pressed

let cnv;
let d;
let g;
function setup() {
  cnv = createCanvas(100, 100);
  cnv.mousePressed(changeGray); // attach listener for
  // canvas click only
  d = 10;
  g = 100;
}

function draw() {
  background(g);
  ellipse(width / 2, height / 2, d, d);
}

// this function fires with any click anywhere
function mousePressed() {
  d = d + 10;
}

// this function fires only when cnv is clicked
function changeGray() {
  g = random(0, 255);
}
Posted by: Guest on December-06-2019
0

if mousepressed javascript

var mouseDown = 0;
document.body.onmousedown = function() { 
  ++mouseDown;
}
document.body.onmouseup = function() {
  --mouseDown;
}
Posted by: Guest on March-23-2020
0

p5 on mouse press

function mousePressed() {
  ellipse(mouseX, mouseY, 5, 5);
  // prevent default
  return false;
}
Posted by: Guest on June-23-2020

Browse Popular Code Answers by Language