0

I have a very simple function that I would like to fire anytime the mouse is idle for around 10 seconds and disappears when the Mouse is moved. I have had a look but finding it difficult to figure out ( I am new to this) thanks in advance!

the animation id like to trigger is this:

   function setup() {
    createCanvas(800, 800);
    frameRate(0.8);
    strokeWeight(30);
}

function draw() {
    stroke(random(500),random(195),random(150));
// strokeweight(random(4,50));
    point (random(800), random(800));
}

I have tried using setTimeout but I seem to be doing something wrong.

becky
  • 11
  • 2
  • 2
    I don't think there's an event for this. Use `setTimeout()` to set a timeout to run in 10 seconds. Then use a `mousemove` listener to stop the timer and start a new one. – Barmar Mar 30 '23 at 21:40
  • Or you can use `setInterval(() => { someFunction() }, 1000);` To execute a function to check the seconds between last mouse move event every second. You should also add a listener: `document.addEventListener('mousemove', () => { window.lastActivity = Date.now();})` And the function could look like this: `function() { var currentTime = Date.now(); if (currentTime - window.lastActivity > 1000 * 10) { Draw() } else { DontDraw() } }` // If you provide a bit more code we could help a bit better :) – Aigarito Mar 30 '23 at 22:05

0 Answers0