This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Sean Keating
Posted Dec 09 - Read on Facebook

I have LayerA that I want to animate to a randomly generated set of coordinates, then immediately and automatically animate it to another, unique, randomly generated set of coordinates, ad infinitum. Simply using repeat: -1 on an animation that uses Math.random for coordinates creates the first random coordinate set, but never regenerates new random coordinates; similar problems with state switching. Recalling a function after AnimationEnd winds up stacking the draw until it crashes.

Hopefully that makes sense…any suggestions on how to force the regeneration of random coordinates for an animation repeatedly without crashing?

Thanks!!!

10 Comments

Ryhan Hassan

Sean Keating

Yay!!! Thanks Ryhan Hassan

Sean Keating

Ryhan Hassan , do you have an idea for how to implement this with a constant animation speed, despite the randomly generated distances? I am trying to figure out how to make the interval timer be a function of the previously run "move"'s time (which I have managed to make a function of the randomly generated distance). Any advice is much appreciated…

Koen Bok

Calculate the distance in pixels from the current position to the next, and do that times a speed (where speed is pixels/second).

Ryhan Hassan

Once you've calculated the duration of your animation, you can use Utils.delay to trigger the next cycle.

Koen Bok

A+

Koen Bok

Hey Ryan, for examples like this, you can quickly copy your code to https://gist.github.com/ and convert the link at http://framer.link.

Sean Keating

Thank you so much for the help, guys!!!

Read the entire post on Facebook