Using the interpolated values while the timer is running
When interpolating between two values, the $value variable holds the current value of the timer. So, if the timer is interpolating between 0.0 and 1.0 (the default values) and has a duration of 5 seconds, then here is how the value should change:| time (seconds) | $value |
| 0.0 | 0.0 |
| 1.0 | 0.2 |
| 2.0 | 0.4 |
| 2.5 | 0.5 |
| 3.0 | 0.6 |
| 4.0 | 0.8 |
| 5.0 | 1.0 |
the changed event is triggered whenever the value changes, so it will constantly send messages while the timer is running.
// a timer that prints out its values as it counts timer ((5.0),, when(changed,("timer value=$value")), when(,("timer is finished")), )
To make this work correctly, however, you have to give the timer two more messages: the startValue and endValue.
These are the values that the timer should interpolate between. By default, it interpolates between 0 and 1; but
most of the time you want to send numbers in a different range. The specific range will depend on what property you're
animating: color values range from 0 to 255, orientation ranges from 0 to 360 degrees on each axis, scale can be any
value but cannot be 0, position can be any value, etc. For this example, we're going to make the hand rotate once,
so the starting angle is 0 and the ending angle is 360.
| time (seconds) | $value |
| 0.0 | 0.0 |
| 0.5 | 60.0 |
| 1.0 | 120.0 |
| 1.5 | 180.0 |
| 2.0 | 240.0 |
| 2.5 | 300.0 |
| 3.0 | 360.0 |
// spinning timer clock ((3.0),(0),(360),, when(changed,clockhand.(0 $value 0))) object clockhand ((clockhand.pfb),(0 5 5),(0 45 0))
You can make this timer loop, again using the back event to restart the timer whenever it gets to the end.
// looping timer clock ((3.0),(0),(360),, when(changed,clockhand.(0 $value 0)), when(,) ) object clockhand ((clockhand.pfb),(0 5 5),(0 45 0))
You can also make it oscillate, by making it change directions when it gets to the front or the back. This example will move the hand back and forth like a metronome:
// back and forth timer clock ((3.0),(-90),(90),, when(changed,clockhand.(0 $value 0)), when(,), when(,) ) object clockhand ((clockhand.pfb),(0 5 5),(0 -90 0))
(c) Ben Chang