let rAnim = r.clone().attr('fill', '#f00').animate(wait).attr('fill', '#0f0')
let rDecl = r.clone().attr('fill', 'blue').animate(new SVG.Spring(wait, 15))
+// var timer = 0
+// rDecl.timeline().source(() => {
+// timer += 100
+// return timer
+// })
+
let runTransformation = (transform) => {
return () => {
- let relative = false
- let affine = false
+ let relative = true
+ let affine = true
r.transform(transform, relative)
rAnim.animate(wait).transform(transform, relative, affine)
rDecl.transform(transform, relative, affine)
shear: 1,
}), 0.1 * wait )
-// setTimeout(runTransformation({
-// origin: 'top-left',
-// translate: [530, 250],
-// rotate: 800,
-// scale: 2,
-// shear: 1,
-// }), wait )
+
+setTimeout(runTransformation({
+ origin: 'top-left',
+ translate: [530, 250],
+ rotate: 100,
+ scale: 2,
+ shear: 1,
+}), wait / 2)
// Save transforms applied to this runner
this.transforms = new SVG.Matrix()
+ this.targets = new SVG.Matrix()
// Looping variables
this._haveReversed = false
return this
},
+ addTarget: function (target) {
+ this.targets = this.targets.lmultiply(target)
+ return this
+ },
+
clearTransform: function () {
this.transforms = new SVG.Matrix()
+ this.targets = new SVG.Matrix()
return this
}
},
.reduce((last, curr) => last.lmultiply(curr))
},
+ _targetTransform (current) {
+ return this._transformationRunners
+ .filter((runner) => runner.id <= current.id)
+ .map(runner => runner.targets)
+ .reduce((last, curr) => last.lmultiply(curr))
+ },
+
addRunner: function (runner) {
this._transformationRunners[runner.id+1] = runner
if (this._frameId == null) {
this._transformationRunners = [{
transforms: new SVG.Matrix(this),
+ targets: new SVG.Matrix(this),
done: true,
id: -1
}]
let current
let currentAngle
var u = 0
+ let firstRun = true
function setup () {
// mid-animation (try turning on the second animation in dirty)
let transformSpace = relative
- ? new SVG.Matrix(element)
+ ? element._targetTransform(this)
: undefined
origin = origin || getOrigin(transforms, element, transformSpace)
start.rotate = currentAngle || start.rotate
}
+ if (firstRun) {
+ this.addTarget(target)
+ firstRun = false
+ }
+
morpher.from(start)
morpher.to(target)
// on this runner. We are absolute. We dont need these!
if (!relative) this.clearTransform()
+ // let {x, y} = new SVG.Point(origin).transform(element._currentTransform(this))
+ // morpher._from.splice(-2, 2, x, y)
+ // morpher._to.splice(-2, 2, x, y)
+
// fix the origin so is in the right space
- if (affine) {
- let currentMatrix = element._currentTransform(this)
- let {x, y} = new SVG.Point(origin).transform(currentMatrix)
- morpher._from.splice(-2, 2, x, y)
- morpher._to.splice(-2, 2, x, y)
- }
+ // if (affine) {
+ // let currentMatrix = element._currentTransform(this)
+ // let {x, y} = new SVG.Point(origin).transform(currentMatrix)
+ // morpher._from.splice(-2, 2, x, y)
+ // morpher._to.splice(-2, 2, x, y)
+ // }
let affineParameters = morpher.at(pos)
currentAngle = affineParameters.rotate