GithubHelp home page GithubHelp logo

jnwspringanimation's People

Contributors

ashfurrow avatar indragiek avatar jbrennan avatar jwilling avatar west0r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jnwspringanimation's Issues

Initial velocity harmonic oscillation

I was doing some research on spring-based animations and found this library while in the process of building a new feature for @NimbusKit. Your implementation is a solid step towards providing spring-based animations, but initial velocity support is key to enabling natural gesture-based animations we're starting to see in more apps and it sadly hasn't been implemented here yet.

This paper by David Morin has a wonderful section on using initial conditions with harmonic oscillators (section 1.1.7). From there we can see that the addition of (velocity / freq) * sin(freq * t) to the harmonic oscillation allows us to incorporate initial velocity into the oscillation.

Sidenote: in practice I found that if the delta (A) is negative then you have to flip the sign of the velocity (v) in order for it not to behave erratically.

I made a grapher file so that I could play with the curves a bit easier. Screenshot follows (can't upload the grapher file to Github sadly). The shorter curve of the two is a damped harmonic oscillation without velocity taken into account (effectively v = 0). The taller curve is a damped harmonic oscillation with an initial velocity of 20 (intuitively: the sign affects which direction we overshoot in, the amplitude by how much).

Velocity pointing toward the delta.
harmonicoscillation

Velocity pointing away from the delta.
harmonicoscillation2

Example of an iOS 7-style spring animation being thrown toward the destination.
harmonicoscillationsin

Example of an initial-velocity spring animation being thrown away from the destination.
harmonicoscillationsout

This is primarily an FYI right now, as I'm not going to use your library in the feature I'm building. The approach I plan to go with will likely not be a subclass of CAAnimation at all, opting instead for a more generalized approach to building key frames for a spring-with-initial-velocity-based tween. The lack of correct transform tweening in this library is problematic, but properly implementing transform tweening requires non-trivial quaternion work, and CAAnimation likely already does that underneath the hood (linked code is not official), so I plan to just let CAKeyFrameAnimation do its magic rather than try to rebuild that code.

Thanks for providing a test bed with which I could more quickly play with this! Your code definitely helped point me in the right direction as far as researching papers and playing with graphs.

Cheers!

  • Jeff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.