Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(documentation) animating shapes along a path example needs rewrite #1303

Closed
opheliagame opened this issue Jun 14, 2023 · 5 comments
Closed

Comments

@opheliagame
Copy link

opheliagame commented Jun 14, 2023

https://svgjs.dev/docs/3.0/tutorials/
The 'Animating shapes along a path' on this page doesn't work anymore I think. I would be willing to write the current version of this if required. lmk :)
referencing #1134 as well

@opheliagame
Copy link
Author

opheliagame commented Jun 14, 2023

I think this example doesnt work anymore.

var canvas = SVG('drawing').size('100%', '100%').viewbox(0,0,800,1000)
  , rect = canvas.rect(100, 100)
  , path = canvas.path("m 357.64532,453.84097 c 17.62007,8.02216 -2.12058,27.70935 -13.33334,29.28571 -30.3859,4.27185 -48.34602,-29.97426 -45.23807,-55.9524 5.5594,-46.46879 56.1311,-70.59787 98.57145,-61.19043 62.28294,13.8058 93.32728,82.57702 77.1428,141.19051 C 453.21679,585.29693 365.67122,623.42358 290.97859,600.26951 196.98554,571.13248 151.71003,464.56996 181.93108,373.84089 218.53281,263.95583 344.23687,211.49702 450.97875,248.84102 576.77037,292.84963 636.43303,437.76771 591.93099,560.50775 540.55162,702.21597 376.3736,769.09583 237.6452,717.41234 80.01319,658.68628 5.9069261,475.21736 64.788247,320.50751 130.84419,146.94643 333.62587,65.607117 504.31214,131.69819 693.80625,205.0718 782.38357,427.18225 709.07382,613.84113")
  , length = path.length()
  
path.fill('none').stroke({width:1, color: '#ccc'})

rect.animate(8000, '<>').during(function(pos, morph, eased){
    var p = path.pointAt(eased * length)
    rect.center(p.x, p.y)
}).loop(true, true)

the following would work

var canvas = SVG('drawing').size('100%', '100%').viewbox(0,0,800,1000)
  , rect = canvas.rect(100, 100)
  , path = canvas.path("m 357.64532,453.84097 c 17.62007,8.02216 -2.12058,27.70935 -13.33334,29.28571 -30.3859,4.27185 -48.34602,-29.97426 -45.23807,-55.9524 5.5594,-46.46879 56.1311,-70.59787 98.57145,-61.19043 62.28294,13.8058 93.32728,82.57702 77.1428,141.19051 C 453.21679,585.29693 365.67122,623.42358 290.97859,600.26951 196.98554,571.13248 151.71003,464.56996 181.93108,373.84089 218.53281,263.95583 344.23687,211.49702 450.97875,248.84102 576.77037,292.84963 636.43303,437.76771 591.93099,560.50775 540.55162,702.21597 376.3736,769.09583 237.6452,717.41234 80.01319,658.68628 5.9069261,475.21736 64.788247,320.50751 130.84419,146.94643 333.62587,65.607117 504.31214,131.69819 693.80625,205.0718 782.38357,427.18225 709.07382,613.84113")
  , length = path.length()
  
path.fill('none').stroke({width:1, color: '#ccc'})

rect.animate(8000).during(function(t){
    var p = path.pointAt(t * length)
    rect.center(p.x, p.y)
}).loop(true, true)

@Fuzzyma
Copy link
Member

Fuzzyma commented Jun 14, 2023

nice! feel free to create a PR to update the docs with a new example :)

@opheliagame
Copy link
Author

@Fuzzyma
just checked the documentation repository and there are jsfiddles embedded so they will have to be edited by the owners

@Fuzzyma
Copy link
Member

Fuzzyma commented Jun 15, 2023

You can just fork them and save a new link

@opheliagame
Copy link
Author

@Fuzzyma
created a new pr here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants