mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-07 12:54:26 +02:00
Updated NeoPixelAnimator object (markdown)
@@ -1,4 +1,37 @@
|
||||
(under construction)
|
||||
This manages the timing and lifetime for animations.
|
||||
|
||||
[NeoPixelAnimator object API]()
|
||||
|
||||
The NeoPixelAnimator manages the timing and lifetime for animations. It does not provide specific animations effects, as these are varied and specific to the application and left for you to create.
|
||||
|
||||
All time values are by default in milliseconds but can be changed to manage long duration animations as well.
|
||||
NOTE: NeoPixelBus::Show() must still be called to push the color state to the physical NeoPixels.
|
||||
NOTE: NeoPixelBus::Show() must still be called to push the color state to the physical NeoPixels.
|
||||
|
||||
## Getting Started
|
||||
For each animation you start, you will need to provide a function that will "apply" the animation with the given progress. The function will called with a AnimationParam structure which contains three properties about the animation to update, one will be the progress.
|
||||
|
||||
To "apply" an animation takes several small pieces of code:
|
||||
|
||||
First, apply a curve to the AnimationParam.progress. The progress is a linear time value from 0.0f at the start of the animation to 1.0f at the end of the animation. The term "linear time" means that progress will map 1:1 to real time. But sometimes what you want is to simulate "mass" so that the animation feels like it starts slow but ends up faster. To do this, we just modify the given progress by using a curve equation that will "ease-in" or "ease-out". More on this latter.
|
||||
|
||||
Second, use the progress to effect the animation. The animation maybe just moving one lit pixel along a strip of pixels, or it maybe blending from one color to another.
|
||||
|
||||
Lastly, apply the changes to the NeoPixelBus. Usually you will just call SetPixelColor somewhere in the animation function; but you won't call NeoPixelBus::Show() as that is always left in the Loop().
|
||||
|
||||
To keep the NeoPixelAnimator running, you will need to call UpdateAnimations() in the Loop() of the sketch. Usually you will follow it with a Show() like this.
|
||||
```
|
||||
animations.UpdateAnimations();
|
||||
strip.Show();
|
||||
```
|
||||
|
||||
## Easing equations
|
||||
|
||||
One very simple equation to use for "ease-in" is the POW (or POWER) function. This raises a value to the power given.
|
||||
```
|
||||
uint8_t progress = POW(param.progress, 2.0f);
|
||||
```
|
||||
The effects due to this equations are that calculated progress will change very little at the beginning and then quickly catch up.
|
||||
Increasing the exponent parameter to the equation will make the effect more dramatic, and decreasing it will make it more linear.
|
||||
|
||||
For more advanced equations with visualizations, see [Gizam.com Easing](http://www.gizma.com/easing/#expo2).
|
||||
|
||||
|
Reference in New Issue
Block a user