Skip to content

Instantly share code, notes, and snippets.

@bmoren
Created November 17, 2015 18:30
Show Gist options
  • Save bmoren/60722881b05622b69a53 to your computer and use it in GitHub Desktop.
Save bmoren/60722881b05622b69a53 to your computer and use it in GitHub Desktop.
idle state for mouse movement in p5.js
//if the mouse is not moving for x time then do something.
mouseIsMoving = false;
function setup(){
createCanvas(windowWidth,windowHeight);
}
function draw() {
if(mouseIsMoving == true){
fill(100);
}else{
fill(0);
}
ellipse(100,100,100,100);
}
function mouseMoved() {
mouseIsMoving = true;
setTimeout(function(){ // this is to delay the execution of the code within, this is pure javaScript
mouseIsMoving = false;
},3000) //it takes a time in MS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment