This commit refactors the getOrigin helper, in order to send the origin to the correct
space. The origin should be expressed in the space of the last animation.
Changes
=======
- Refactored the getOrigin helper
- Added a simple example to the dirty file to test multiple transformations
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))
-// // Move once
-// setTimeout(() => {
-// let trans = {tx: 500, ty: 300}
-// r.transform(trans, true)
-// // rAnim.animate(wait, 0, 'start').transform(trans, true)
-// rDecl.transform(trans, true)
-// }, wait)
-
-// Move again
-setTimeout(() => {
- let transform = {
- origin: 'top-left',
- translate: [530, 250],
- rotate: 300,
- scale: 2,
- shear: 1,
+let runTransformation = (transform) => {
+ return () => {
+ let relative = false
+ let affine = false
+ r.transform(transform, relative)
+ rAnim.animate(wait).transform(transform, relative, affine)
+ rDecl.transform(transform, relative, affine)
}
- let relative = true
- let affine = false
- r.transform(transform, relative)
- rAnim.animate(wait).transform(transform, relative, affine)
- rDecl.transform(transform, relative, affine)
-}, 0.1 * wait )
-
-
-// declaritive relative (affine/nonaffine)
-// declaritive absolute non affine
-// normal non affine relative
-
-// D N
-// R
-// A
-
+}
+setTimeout(runTransformation({
+ origin: 'top-left',
+ translate: [530, 250],
+ rotate: 300,
+ scale: 2,
+ shear: 1,
+}), 0.1 * wait )
+
+// setTimeout(runTransformation({
+// origin: 'top-left',
+// translate: [530, 250],
+// rotate: 800,
+// scale: 2,
+// shear: 1,
+// }), wait )
}
-function getOrigin (o, element, relative) {
+function getOrigin (o, element, inSpace) {
// Allow origin or around as the names
let origin = o.around == null ? o.origin : o.around
let ox, oy
}
// Transform the origin into the current reference frame
- if ( relative ) {
- let matrix = new SVG.Matrix(element)
- let originRelative = new SVG.Point( ox, oy ).transform(matrix)
+ if ( inSpace ) {
+ let originRelative = new SVG.Point( ox, oy ).transform(inSpace)
ox = originRelative.x
oy = originRelative.y
}
// make sure element and origin is defined
element = element || this.element()
- origin = origin || getOrigin(transforms, element, relative)
-this.element().parent().ellipse(50, 50).center(...origin)
+ // TODO: Give me all matricies concatenated, up until this matrix,
+ // for example, if I have M = E D C B A
+ // If I'm about to run D, I want transform space to be
+ // C * B * A
+ // Where C B and A are the current morpher targets
+ // The solution I've added here won't work if we interrupt an animation
+ // mid-animation (try turning on the second animation in dirty)
+
+ let transformSpace = relative
+ ? new SVG.Matrix(element)
+ : undefined
+ origin = origin || getOrigin(transforms, element, transformSpace)
// add the runner to the element so it can merge transformations
element.addRunner(this)