I have many reasons for writing this bit of code, and of course many more for sharing it, even if I haven’t checked to see if anyone has written it already…
I wanted a quick bit of code to allow me to work out the points on a curve without having to actually wait for time to elapse because I want to plot the course something will take, before it takes it.
Therefore, a piece of code which calls the easing functions without using transition.to or transition.from is required.
Here it is - the functions declared below are there for explanation and because I developed this on the “Lua: demo” (http://www.lua.org/cgi-bin/demo) page (copy/paste it direct - I don’t have access to a mac right now):
[lua]-- this is the ‘easeOut’ function copied from the code exchange page
function easeOut(t, tMax, start, delta)
return start + (delta * _easeOut(t/tMax))
end
– this is the ‘behind the scenes’ function copied from the same page
function _easeOut(ratio)
local invRatio = ratio - 1.0
return (invRatio*invRatio*invRatio) + 1.0
end
– the loop to run to get the values without using time/transition…
local tmax = 10 – total number of iterations (would be the ‘time’ property usually)
local start = 0 – the starting value
local delta = 100 – the destination value
– this loop actually outputs 11 iterations, but that’s ok (change t=0 to t=1 if its not for you)
for t=0, 10 do
local value = start + easeOut(t, tmax, start, delta)
print(t … ': ’ … value) – prints the value derived from the iteration
end[/lua]
Of course, this could be used to calculate a ‘pause’ point during a transition. All you’d need is a table containing the parameters of the transition before it starts and to know at which point in time the transition is stopped. Restarting would be a different issue, but if you replaced the transition call completely with your own function called from ‘eventFrame’ you could have a pause/continue function which uses the same easings.
(Phew… I hope I’m not reinventing the wheel here…)
Matt. [import]uid: 8271 topic_id: 3786 reply_id: 303786[/import]