rpath
New Member
Posts: 1
|
Post by rpath on Apr 22, 2021 18:54:38 GMT
I'm experimenting using the generativepy library to create tweens for color changes over time in LED light strips controlled with Python. I'm wondering if anyone can provide information on how to set timing for a tween - that is, how long a tween takes to complete. I know that tweens are based on frames for their length...is there a function to set the frame rate when a tween runs so that I can easily control how many seconds a tween lasts? And, what is the default frame rate for a tween (or the library in general)?
|
|
|
Post by Martin McBride on Apr 24, 2021 9:04:41 GMT
Tweens are entirely frame based. You define the tween sequence in terms of frame count, and you access the tween value using frame index.
If you want to use time, you will need to convert time into a frame index, using a function like this:
FRATE = 25
def time2frame(t): return int(time*FRATE)
Where FRATE is your desired frame rate. Higher values give more accurate timings, but make the tween array larger. A value of 25 makes each frame 0.02s long, which is fine for most uses.
Then to create a tween you can use something like:
tween = Tween(0.0).to(1.0, time2frame(10.0)).to(0.0, time2frame(5.0))
This example creates a tween that lasts for 15 seconds. It starts at zero, rises to 1.0 over the first 10 seconds, then falls back to zero over the next 5 second.
To get the tween value at, say, 7.2 seconds, use:
value = tween[time2frame(7.2)]
Hope that helps.
|
|