popmotion icon indicating copy to clipboard operation
popmotion copied to clipboard

{Feature request] Animating a vector

Open matthiasferch opened this issue 4 years ago • 1 comments

I would like to be able to animate a 2D vector, like so:

interface vector {
  x: number,
  y: number;
}

const from = { x: 0.0, y: 0.0 };
const to = { x: 4.0, y: 2.0 };

animate<vector>({ from, to, onUpdate: (vector) => console.log(vector) });

I would like to try adding support for this myself but I'm not sure where to start. Could you point me in the right direction?

matthiasferch avatar Feb 23 '21 15:02 matthiasferch

Perhaps you've already figured this out. In case it could help anyone, the included interpolate function can be used for that.

const fromTo = interpolate(
  [0, 1],
  [
    { x: 0.0, y: 0.0 },
    { x: 4.0, y: 2.0 }
  ]
)
animate({ onUpdate: v => console.log(fromTo(v)) });

I guess you could create an animate wrapper that automates it too.

stokesman avatar Aug 02 '21 05:08 stokesman