// anim.transform({px: p.x - 100, py: p.y - 100})
// //anim.center(p.x, p.y)
// })
-
+/*
let canvas = SVG('#canvas')
+let rectangle = canvas.rect(100, 200).move(100, 0)
+
+let bbox = rectangle.bbox()
+
+var timer = 0
+rectangle.timeline().source(() => {
+ timer += 2
+ document.querySelector('#absolute span').textContent = timer
+ return timer
+})
+rectangle.animate().transform({
+ rotate: 90,
+ origin: [bbox.cx, bbox.cy]
+})*/
+
+
+let canvas = SVG('#canvas')
// Make the green rectange
canvas.rect(200, 400).move(200, 400)
.attr('opacity', 0.3)
.attr('opacity', 0.3)
.addClass('pink')
.transform({ px: 100, py: 500, origin: 'top-left' })
- .animate()
- .transform({ rotate: 500, origin: 'center' })
+
+
+ var timer = 0
+ a.timeline().source(() => {
+ timer += 1
+ document.querySelector('#absolute span').textContent = timer
+ return timer
+ })
+
+a.animate()
+ .transform({ translate: [200, 200], rotate: 500, origin: 'center' }, true)
// Put an ellipse where we expect the object to be
canvas.ellipse(30, 30).center(100, 500)
// r.step(1200) // should be 0.1s
// r.step(-300) // should be 0.9s
-
+/*
var timer = 0
SVG('svg').viewbox(-150, -150, 1000, 1000)
let rec1 = SVG('<rect>').addTo('svg')
.transform({
scale:2
})
-
+*/
// .animate(400, 0, 'absolute')
// .transform({
// rotate: 360,
}
}
-function getOrigin (transforms, element) {
+function getOrigin (o, element) {
// Allow origin or around as the names
origin = o.around == null ? o.origin : o.around
if ( typeof origin === 'string' || origin == null ) {
// Get the bounding box of the element with no transformations applied
const string = (origin || 'center').toLowerCase().trim()
- const { height, width, x, y } = this.bbox()
+ const { height, width, x, y } = element.bbox()
// Set the bounds eg : "bottom-left", "Top right", "middle" etc...
const ox = o.ox || string.includes('left') ? x
// 4. Now you get the delta matrix as a result: D = F * inv(M)
transform: function (transforms, relative, affine) {
- if (this._tryRetarget('transform', transforms)) {
+ if (this._isDeclarative && this._tryRetarget('transform', transforms)) {
return this
}
transforms.origin = origin
let sanitisedTransforms = formatTransforms(transforms)
- morpher.from({origin})
+ morpher.from(formatTransforms({origin}))
- var from = morpher.from()
- var indexOfOffset = from.indexOf('offset')
+ var to = morpher.to()
+ var indexOfOffset = to.indexOf('ox')
if(indexOfOffset > -1) {
- let to = morpher.to()
- to[indexOfOffset+1] = origin
- to[indexOfOffset] = 'origin'
+ to.splice(indexOfOffset, 4, 'ox', origin[0], 'oy', origin[1])
}
this.element().addRunner(this)
return morpher.done()
}, true)
- this._rememberMorpher('transform', morpher)
+ this._isDeclarative && this._rememberMorpher('transform', morpher)
return this
}
}, true)
- this._rememberMorpher('transform', morpher)
+ this._isDeclarative && this._rememberMorpher('transform', morpher)
return this
},