07-Animation
07-Animation
Animation 1
Animation
Animation 3
Frame Rate
* each frame is sent progressively in two parts: odd “scanlines”, even “scanlines”,
so communication speed is technically 60 Hz for NTSC and 50 Hz for PAL
Animation 4
Critical Flicker Frequency* (CFF)
CFF is typically
around 60 – 90 Hz
▪ in simplekit
▪ in your program
Animation 7
Animation by Simulation
Animation 8
simulation
Animation 9
Timers
▪ A timer needs
- a duration
- a start time
- an update function to check if timer is finished
- a method to check if timer is running
- (usually) a callback function to call when timer is finished
Animation 10
timer simpleTimerDemo()
Animation 11
timer callbackTimerDemo()
Animation 12
Tweening
Tweening Parameters
startValue is the starting value for the tween (keyframe 1)
endValue is the end value for the tween (keyframe 2)
duration is the duration for the tween
startTime is when the tween begins
Tweening Calculation
1) Calculate proportion of time completed so far:
t = (time – startTime) / duration
2) Interpolate start and end value to get current tweened value:
value = startValue + (endValue – startValue) * t
Animation 13
lerp function
linear interpolation
▪ smoothly interpolate changes from one value to another
▪ lerp is a fundamental part of animation tweening
Animation 14
tweening
▪ Type
type EasingFunction = (t: number) => number;
▪ Common functions
exponent changes the
const flip = (t) => 1 - t; "amount" of easeOut
Animation 17
easing
...
Animation 18
Easing Function Resources
▪ http://robertpenner.com/easing/
▪ https://greensock.com/docs/v3/Eases
▪ https://www.febucci.com/2018/08/easing-functions/
Animation 20
manager
class AnimationManager {
protected animations: Animater[] = [];
add(animation: Animator) {
this.animations.push(animation);
...
}
update(time: number) {
// update every animation currently running
this.animations.forEach(
(a) => a.update(time));
Animation 22
Keyframing Example
Example 1
when time is 800,
time targetValue tween keyframe 0 and keyframe 1:
t = (800 – 0) / (1000 – 0)
0: 0 100
value = 100 + t * (300 - 100)
keyframes
Animation 23
keyframes
▪ Keyframer object
- find interval in keyframe array using time
- tween to get current value
- call callback
▪ Comments
- how to insert pauses as keyframes?
Animation 24
Animation Using Built-in Timers
pseudo code
Animation 25
dom-timers demoIntervalTimer()
Animation 28
Animation using Java Util Timer
import java.util.* This code is Kotlin with JavaFX
// create timer
val timer = Timer()
// create timer
val timer = Timer()
object : TimerTask() {
override fun run() {
// runs the code on the JavaFX thread
Platform.runLater {
aniScene.x += 1.0 // animate parameter
aniScene.draw() // redraw updated scene
}
}
},
0, 1000/60
)
Animation 30
Standard Animation API and Libraries
Video demo:
https://vault.cs.uwaterloo.ca/s/trNbEgP24p4mbas
Animation 32