Let’s assume that the lamp off would have a black color. When switching colors between frames, even at a frameRate of 60, you will see actually a lamp “color on” 30 times a second. (the other frame was black) If you have an Arduino you could test at what range you still would notice a flickering. It’s even different for each person. Would be nice to test.
Even increasing the FPS by the frameRate function, placing it around 100 or more, we can still see an Oscillation between the frames of light on and light off.
In theory, just running at 60 fps, we couldn’t see this oscillation, however we could see it even increasing the FPS to 100 or more with the frameRate function …
The idea was that at 60 fps the draw function would switch frames so fast that it would create an illusion that the lamp was always on … but that is not the case, we can see an oscillation in this “simulation”.
I was wondering what the cause of this is or what is wrong with my code.
I will not make a code for an arduino, my class of students has not yet reached that level hehehe
The maximum frameRate depends on the time needed to process what you are drawing, on your computer processing power, and sometimes on process interference from other not sketch related computer tasks. If you for instance draw just an ellipse on the background it will reach a high frameRate. With the code below I get a frameRate of about 5000 on my modest pc;
Also once again, the lamp goes only 30 times per second on and off. Not 60 times.
Really, this frameRate even set above 60, it doesn’t work …
Literally it only reaches a maximum of around 60 and this oscillation between 57, 58, 59, 60, 61, makes us able to perceive the flashing light.
The problem with frameRate is that even specifying to run only at 60 fps, it can’t … and it can’t go beyond 60 fps either.
So making this “simulation” more realistic about turning the light on and off is not possible.
It may work by adjusting the frequency of the monitor I use to over 60 fps, but I don’t want to do that.
This case was interesting, to know that there are limits in this frameRate that does not depend on the code.
The topic is actually interesting.
I believe that the irregularity also comes from the fact that frameRate is given by an average of 10 frames(?). Meaning that there can be long pauses (relatively) between frames.
But that’s a guess. Maybe someone with a deeper core knowledge can respond.
I also thinking of harmonics maybe.
The code below gives a more stable value(resulting gray) at 60 f/s on my pc.
The frameRate() that you set is capped at the refresh rate of your monitor.
Lower values than refresh rate can be set.
My monitor has a refresh rate of 60; I can set frameRate(100) but it will be capped at 60. https://p5js.org/reference/#/p5/frameRate
With Processing Java:
Attempts to achieve the frameRate() that you set but is limited by processor (GPU and CPU).
The frameRate() is not capped by Processing but you will not see all the frames if you set this higher than the refresh rate. https://processing.org/reference/frameRate_.html
“The refresh rate (Hz) of your monitor does not affect the frame rate (FPS) your GPU will be outputting. However, if your FPS is higher than your refresh rate, your display will not be able to display all of the frames your computer is producing, so although the refresh rate doesn’t technically limit the frame rate, it does effectively set a cap.”
p5.js has deltaTime to easily inspect inter-frame delay without averaging.
I still was thinking of that and I remembered that some years ago It was very hard for me to fall asleep. So I made a device that really helped me. I used some old glasses where I build some LEDs in, and an Arduino, which started flickering at the highest brainwave frequency Beta (35 Hz) down to Alpha (12), Theta (8), and finally Delta (4), with programmable time lapses.
I remember that I could see 60 Hz flickering. And in my youth, when fluorescent lamps still used around 50Hz, I often was annoyed by that. The common bulb has an afterglow, so it doesn’t actually switch off.
Here is an interesting article about light flickering.