(Summary) I want to reduce CPU usage as much as possible when the program is static. When the program is dynamic, I want to increase the CPU usage as much as possible.
If there is a good way, please help. Please tell us.
Leave the frameRate at the default. When you’re animating, it will run at your monitor’s refresh rate (or is it locked to 60 fps? I’m not sure.) When you want to pause or just show a static image, use noLoop(). If you want to update a static image from a key press or mouse action, call redraw() to trigger another call to draw(). If, and only if, you want to start animating again, call loop().
There are cases where it has to be turned on 365 days a year
There is a case where it is raised for a few hours.
The same situation now is when it has to be turned on 365 days a year.
Therefore, it shows how to reduce the burden on the CPU through noLoop() and loop().
What should happen when it is “turned on”? Is the program drawing anything? Or is it just waiting for a key or mouse or network event? If it is animating, then you would want it to be looping. If it is just waiting for external events, then you could call noLoop() and it should be using very little resources.
frameRate(1) would call draw() once per second. I don’t think Processing goes below that, but you could use a Java timer (which I’ve never used, so I don’t know how to do it) to call redraw() only every minute or hour or once a day if you wished.
Use your favorite web search engine to read about “Java Timer”. This example calls draw() every 3 seconds. The TimerTask object’s run() method is called based on how you set it up using schedule() which takes an initial delay and the time period between runs in milliseconds as a long int. If you wanted draw() to run every four hours, you would give the time period as 436001000L.
If you want to change the period between calls, there are other ways to schedule a Timer. Look at Oracle’s Java documentation for what you need. For instance, instead of setting a recurring timer like schedule() does, you could compute the next update time in the task’s run().
The EXAMPLE code that you show would be a different way to create a timer but which depends on the draw() function running continuously. That would use up more CPU which is not what you want.
If you have a Java Timer call redraw() and use noLoop(), then draw() will not be called at all until the timer triggers. Using the Java Timer, you would remove the code you have below the // EXAMPLE --- comment and just include in draw() whatever you want Processing to do each time the timer goes off.
Put the noLoop() in setup(). You don’t need to call it each time draw() runs.