diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-05-01 20:17:24 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-05-01 20:17:24 +1000 |
commit | 897bbfa075055097d64d42d7a32952bec9c75665 (patch) | |
tree | 648b309560000a18f51e689f13bd22ca16f468af /src/animation/Controller.js | |
parent | 9a17f412b894c21db7f81bcc910981443477957f (diff) | |
download | svg.js-897bbfa075055097d64d42d7a32952bec9c75665.tar.gz svg.js-897bbfa075055097d64d42d7a32952bec9c75665.zip |
added specs for animation files except runner, fixed a few things
Diffstat (limited to 'src/animation/Controller.js')
-rw-r--r-- | src/animation/Controller.js | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/animation/Controller.js b/src/animation/Controller.js index 35fa1ae..972679e 100644 --- a/src/animation/Controller.js +++ b/src/animation/Controller.js @@ -9,7 +9,7 @@ The base stepper class that will be function makeSetterGetter (k, f) { return function (v) { - if (v == null) return this[v] + if (v == null) return this[k] this[k] = v if (f) f.call(this) return this @@ -104,9 +104,9 @@ Easing Functions ***/ export class Ease extends Stepper { - constructor (fn) { + constructor (fn = timeline.ease) { super() - this.ease = easing[fn || timeline.ease] || fn + this.ease = easing[fn] || fn } step (from, to, pos) { @@ -155,10 +155,10 @@ function recalculate () { } export class Spring extends Controller { - constructor (duration, overshoot) { + constructor (duration = 500, overshoot = 0) { super() - this.duration(duration || 500) - .overshoot(overshoot || 0) + this.duration(duration) + .overshoot(overshoot) } step (current, target, dt, c) { @@ -195,13 +195,8 @@ extend(Spring, { }) export class PID extends Controller { - constructor (p, i, d, windup) { + constructor (p = 0.1, i = 0.01, d = 0, windup = 1000) { super() - - p = p == null ? 0.1 : p - i = i == null ? 0.01 : i - d = d == null ? 0 : d - windup = windup == null ? 1000 : windup this.p(p).i(i).d(d).windup(windup) } @@ -215,7 +210,7 @@ export class PID extends Controller { var p = target - current var i = (c.integral || 0) + p * dt var d = (p - (c.error || 0)) / dt - var windup = this.windup + var windup = this._windup // antiwindup if (windup !== false) { @@ -232,7 +227,7 @@ export class PID extends Controller { } extend(PID, { - windup: makeSetterGetter('windup'), + windup: makeSetterGetter('_windup'), p: makeSetterGetter('P'), i: makeSetterGetter('I'), d: makeSetterGetter('D') |