forked from zzorn/animator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animator.h
99 lines (74 loc) · 3.68 KB
/
animator.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
animator.h - 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.
*/
#ifndef animator_h
#define animator_h
// Include arduino default lib
#include "WProgram.h"
typedef long (*ContinuousFunction) (long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
typedef long (*ChangeFunction) (long timeSinceStart_ms, long startValue, long targetValue);
//AnimationFunction numeral[10] = {zero,one,two,three,four,five,six,seven,eight,nine};
// Continuous functions
long pause(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
long sine(long timeSinceStart_ms, long startValue, long wavelength, long amplitude);
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 setRange(int minValue, int maxValue);
void setRepeat(bool repeating);
void setPwmScaling(int division, int shift);
void setAutomaticPwmScaling(); // Scales based on current range.
void setPwmOutPin(int pwmPin);
void detachPwmOutPin();
Property animate(ContinuousFunction function);
Property animate(ContinuousFunction function, long duration_ms);
Property animate(ContinuousFunction function, long duration_ms, long wavelength_ms);
Property animate(ContinuousFunction function, long duration_ms, long wavelength_ms, int amplitude);
Property animateTo(int target);
Property animateTo(int target, long duration_ms);
Property animateTo(int target, long duration_ms, ChangeFunction changeFunction);
Property animateTo(int target, long duration_ms, ChangeFunction startChange, ChangeFunction endChange);
// 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?
bool isFinished();
void waitUntilFinished();
void stop();
void pause();
void resume();
void setPaused(bool paused);
void update(long millisecondsSinceLastCall);
static void updateAll(long time);
static void updateAll();
// Animate to
//
private:
int _value;
};
#endif