diff options
author | Saivan <savian@me.com> | 2018-06-26 22:42:47 +1000 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-06-26 22:42:47 +1000 |
commit | 6353b3d2f43f5899ebecab13b82ecadacdbb69b3 (patch) | |
tree | 48c8795404e3e06d9c76cdc897465ac8b3c2f754 /playgrounds/transforms | |
parent | 0f1feefa9e8738c09d3a55bc8d15d832db36753e (diff) | |
download | svg.js-6353b3d2f43f5899ebecab13b82ecadacdbb69b3.tar.gz svg.js-6353b3d2f43f5899ebecab13b82ecadacdbb69b3.zip |
Allowed the origin to stay fixed as we animate transforms
This commit start to remove the expensive bbox calculation by assuming
that the origin stays at a fixed point during an animation. This is a
good assumption as transforms don't change the bbox of the element.
Changes
=======
- Refactor the Element.transform function
- Make a getOrigin function to call the bbox only one time
Diffstat (limited to 'playgrounds/transforms')
-rw-r--r-- | playgrounds/transforms/transforms.html | 8 | ||||
-rw-r--r-- | playgrounds/transforms/transforms.js | 28 |
2 files changed, 22 insertions, 14 deletions
diff --git a/playgrounds/transforms/transforms.html b/playgrounds/transforms/transforms.html index 89dc419..a165dd9 100644 --- a/playgrounds/transforms/transforms.html +++ b/playgrounds/transforms/transforms.html @@ -17,13 +17,7 @@ box in your console with its variable name: <code>mover</code> </p> - <svg viewBox="0 0 1500 1500"> - - <rect id="old" x=200 y=400 width=200 height=400 class="green"/> - <rect id="new" x=200 y=400 width=200 height=400 class="pink"/> - <ellipse id="new" cx=800 cy=500 rx=10 ry=10 class="dark-pink"/> - - </svg> + <svg viewBox="0 0 1500 1500" id="canvas"></svg> </body> diff --git a/playgrounds/transforms/transforms.js b/playgrounds/transforms/transforms.js index b27e1c3..1918cd7 100644 --- a/playgrounds/transforms/transforms.js +++ b/playgrounds/transforms/transforms.js @@ -1,9 +1,23 @@ -let mover = SVG.select("#new")[0] -mover.transform({ - position: [800, 500], - origin: [200, 400], - skew: [20, 0], - rotate: 30, -}) +let canvas = SVG('#canvas') + +// Make the green rectange +canvas.rect(200, 400).move(200, 400) + .attr('opacity', 0.3) + .addClass('green') + +// Make the pink rectangle +let a = canvas.rect(200, 400).move(200, 400) + .attr('opacity', 0.3) + .addClass('pink') + .transform({ px: 100, py: 500, origin: 'top-left' }) + +debugger + a.animate() + .rotate({ rotate: 500, origin: 'top-right' }) + +// Put an ellipse where we expect the object to be +canvas.ellipse(30, 30).center(100, 500) + .attr('opacity', 0.3) + .addClass('dark-pink') |