Simple variable question

Hi I am quite new to processing and I'm just trying to figure out how to do one simple thing. I have an integer set at 255 as a gobal variable. I want to use the mousePressed function to make this variable move down to 100 over the course of about 5 seconds, then after it hits 100 go back up to 255 and keep repeating. Im really lost on how to do this.

Answers

  • Answer ✓

    Set a global boolean to true in your mousePressed() function that records that the mouse has been pressed. Also, record the current value of millis() (in another global int), since you want to do things over the next 5 seconds starting from this time.

    In draw(), check if the mouse has been pressed. If it has, determine how much time (in milliseconds) has elapsed between when the mouse was pressed (that's the time you just remembered in mousePressed()) and now (millis() is now). Then use map() to map that amount of elapsed time from some range (0 to 5000, perhaps?) to some other range (0 to 155, perhaps?).

    If that amount of elapsed time is over 5000 milliseconds, what steps will you need to take to be prepared for the next 5000 milliseconds?

    Attempt to write this yourself first. POST YOUR CODE of your attempt if you need any more help.

Sign In or Register to comment.