– Here is the FPS template I promised in my(Coding On Napkins) comment
– in http://codea.io/talk/discussion/comment/51093#Comment_51093
– Why do programmers care about “Frames Per Second(FPS)”?
– In CODEA, draw() is called 60 times(frames) per second
– or less - much less if the code in draw() takes too long.
– Screen redraw time and response to screen touches
– can become so slow that the user may think your program
– has stopped or gone into an infinite loop.
– This happens because touched() is NOT called until draw() ends.
– One of the hardest tasks a CODEA programmer has is dividing
– a long running task into small enough parts that
– the program remains responsive to user control.
– The most frustrating modern day user “experience” is not being able
– to stop a program or task that the user did not mean to start.
– This very important topic is one I do want to discuss
– another day.
– But back to FPS!
– The CODEA variable DeltaTime gives the time since the last
– call to draw() in seconds. 1/DeltaTime=FPS but it changes
– with every draw().
– You have to provide code to keep a history of DeltaTime’s
– value and interpret what those values mean to your program’s
– response time. That is the topic of this example.
– The easiest way is just to show the instantantious values
– less than, say, 55fps.
– Here is the code:
-- in setup()
retainedFPS=0
-- in draw()
monentaryFPS=1/DeltaTime
if (monentaryFPS<55) then
retainedFPS=monentaryFPS
end
text(string.format("fps=%d",retainedFPS),x,y)
print(string.format("fps=%d",retainedFPS)..\
)
– The text shows on screen the last “instantanious” value
– and the print records a log into the console.
– In my discussion, I was thinking of a more elaborate
– graphic display with bars for, say,
– inRanges({{55,40},{39.9,20},{19.9,10},{9.9,-1000}}),
– but the simpler code will be enough in many cases.
– I will finish the graphic version because I want it for
– one of y projects.