ninjadev / nin

nin is ninjatool
https://www.npmjs.com/package/ninjadev-nin
Apache License 2.0
343 stars 15 forks source link

Add interpolated BEAN number for animation use #470

Open lionleaf opened 6 years ago

lionleaf commented 6 years ago

Adds new global variable INTERBEAN, which is a float that is interpolated between BEAN numbers, in a linear way between frames. This can be used to key animations without getting the lower frame rate of BEAN.

Discussion to be had here: Can we instead change BEAN to have fractional values? The way I see it that would be the preferred option here, but I'm afraid of changing behaviour if people have already relied on it being an integer somewhere.

lionleaf commented 6 years ago

INTERBEAN is also a bit long name for a variable you might repeat a ton of times while writing animations, anyone have a better suggestion? FBEAN? (float bean) BEAF?

lionleaf commented 3 years ago

Not sure I follow. This PR would make INTERBEAN piecewise linear with the slope depending on bpm and fps already, right?

sigvef commented 3 years ago

There is no guarantee that there is a fixed number of frames in each BEAN. In this example, bpm is 125, subdivision is 4 and fps is 60.

Not a completely straight line:

So, if you were to use INTERBEAN e.g. like this:

this.ball.position.x = Math.sin(INTERBEAN);

then the animation will speed up and slow down ever so slightly all the time.

lionleaf commented 3 years ago

Yes, we agree about the current behaviour then. It is piecewise linear and certainly not just a straight line.

I went back to find the original use case that motivated this:

https://github.com/ninjadev/revision-invite-2018/blob/5b66355f75b18e894dcfcd2d257420f4dbee99d9/src/OrthoCubeNode.js#L29

Basically it's used for animations between states that complete on a beat. (In this case the rotation of the cube).

And since there could be different amounts of frames between beats you do want the rotation speed to vary.

You're right though, this could easily be used in scenarios where you want/expect a constant speed.

An alternative that would also solve the motivating scenario would be a number that goes 0.0 -> 1.0 between each beat?

lionleaf commented 3 years ago

Also happy to make the decision that this is more confusing than useful and close this PR.

sigvef commented 3 years ago

Maybe we can just give it a name that implies the piece-wise-ness strongly enough and merge that.