andrewMacmurray / elm-simple-animation

stateless animation utils for Elm
https://package.elm-lang.org/packages/andrewMacmurray/elm-simple-animation/latest/
MIT License
50 stars 3 forks source link

Fix opacity animation not occuring #11

Closed MartinSStewart closed 3 years ago

MartinSStewart commented 3 years ago

I ran into an issue where I'd fade a black rectangle from 1 opacity to 0.5 and then later, try to fade it back from 0.5 to 1. The problem was that the fade back part would instead instantly jump to 1 opacity. The reason this was happening is because, when the keyframe was given a name, it would use this function

rounded : Int -> Float -> String
rounded n val =
    String.fromInt (round val * n)

which would cause both 0.5 and 1 to round to 1 and then be multiplied by n (rather than be multiplied by n and then rounded). So the keyframe animation from 1 to 0.5 and the keyframe animation from 0.5 to 1 would have the same name which seemed to cause the second animation to get skipped.

This PR corrects this mistake so rounded correctly scales by n first and then rounds.