forked from zzorn/animator
/
animator.cpp
80 lines (60 loc) · 3.08 KB
/
animator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
animator - Library for animating properties.
Created by Hans Häggström, 2010.
Released under the new BSD license.
Useful for various smoothly blinking leds, rgb led animation sequences, servo animations, sound wave generation, and many other things.
*/
#include "animator.h"
// Continuous functions
long pause(long timeSinceStart_ms, long startValue, long wavelength, long amplitude) {return startValue; }
long sine(long timeSinceStart_ms, long startValue, long wavelength, long amplitude) {return sin(timeSinceStart_ms) }
long square(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long sawtooth(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long pinkNoise(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long brownNoise(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long whiteNoise(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long noise(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
// Change functions
long jump(long timeSinceStart_ms, long startValue, long targetValue);
long slide(long timeSinceStart_ms, long startValue, long targetValue);
long smooth(long timeSinceStart_ms, long startValue, long targetValue);
long snap(long timeSinceStart_ms, long startValue, long targetValue);
long bounce(long timeSinceStart_ms, long startValue, long targetValue);
long wave(long timeSinceStart_ms, long startValue, long targetValue);
long randomWalk(long timeSinceStart_ms, long startValue, long targetValue);
long speed(long timeSinceStart_ms, long startValue, long targetValue);
long brake(long timeSinceStart_ms, long startValue, long targetValue);
class Property
{
public:
Property(int initialValue);
int get();
void set(int newValue);
void setMin(int minValue);
void setMax(int maxValue);
void setLimits(int minValue, int maxValue);
void setRepeat(bool repeating);
Property animate(function: ContinuousFunction);
Property animate(function: ContinuousFunction, long duration_ms);
Property animate(function: ContinuousFunction, long duration_ms, long wavelength_ms);
Property animate(function: ContinuousFunction, long duration_ms, long wavelength_ms, int amplitude);
Property animateTo(target: int);
Property animateTo(target: int, long duration_ms);
Property animateTo(target: int, long duration_ms, changeFunction: ChangeFunction);
Property animateTo(target: int, long duration_ms, startChange: ChangeFunction, endChange: ChangeFunction);
// Copy another property but apply some filter function
// Fade between two other properties using a change function
// Mix two other properties using a continous function
// Change this property by another property
// Follow another property with some inertia, acceleration, friction, etc - can this be implemented simply using some other functions?
void pause();
void play();
void stop();
void clear();
void update(long millisecondsSinceLastCall);
// Animate to
//
private:
int _value;
};
#endif