Open adaburton opened 2 years ago
I think it would be good to add some tests for this function (check for expected values).
We'll also need a function needs to get the animation progress based on time using std::time::Duration for both time delta and animation speed. Then, adding a test that makes sure the beginning and end of the animation are slower than the middle.
Let me know if you have any questions.
I based the function off of the red curve pictured in this graph. https://en.wikipedia.org/wiki/B%C3%A9zier_curve#/media/File:Bezier_basis.svg
You could convert a linear animation to this curve by first rasterizing the animation into discrete frames, and then converting as follows:
for frame in frames param * = bezier(frame/sizeof(frames))
something like that. This is a pretty hacky solution though, and I understand the need for tests. But this was the only solution I could think of that was as simple as taking a single f32 and returning one back.
Yeah, I guess there's a few options:
I should mention that the Twang bezier function is less tunable than the CSS bezier animations. That might be ok for this project though. Just something to keep in mind.
Actually, I just did some experimenting and it's more or less basically an x² algorithm.
Here's what I'm going to use for bezier curve in twang if you choose to base it on that implementation (where performance is big concern): https://www.desmos.com/calculator/3gf8alz4zy (time from -1 start to +1 end)
A nice benefit is that it's a linear function.
I'm wondering if the way we implement this should depend on how animations are implemented, and therefore we should wait until then to worry about this.
Possibly. I'll let you make the call if you want to wait until more things are in place to implement this.
Added free function bezier to calculate the bezier coefficient for a given point in an animations cycle to resolve #9