2017-06-25 04:45:03 +00:00
|
|
|
module AnimationHelpers exposing (..)
|
|
|
|
|
|
|
|
import Types exposing (Range)
|
2017-06-27 22:25:06 +00:00
|
|
|
import Svg.Path exposing (Point)
|
2017-06-25 04:45:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
calculateAnimation : Int -> Int -> Range -> Float
|
|
|
|
calculateAnimation current cycle range =
|
|
|
|
let
|
|
|
|
( start, end ) =
|
|
|
|
range
|
|
|
|
|
|
|
|
rangeDiff =
|
|
|
|
end - start
|
|
|
|
in
|
2017-06-25 05:06:23 +00:00
|
|
|
(toFloat (current % (cycle + 1))) / (toFloat (cycle)) * rangeDiff + start
|
2017-06-27 22:25:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
movePosition : Point -> Float -> Float -> Point
|
|
|
|
movePosition position direction distance =
|
|
|
|
let
|
|
|
|
rads =
|
|
|
|
degrees direction
|
|
|
|
|
|
|
|
x =
|
|
|
|
(Tuple.first position) + (cos rads * distance)
|
|
|
|
|
|
|
|
y =
|
|
|
|
(Tuple.second position) + (sin rads * distance)
|
|
|
|
in
|
|
|
|
( x, y )
|
|
|
|
|
|
|
|
|
2017-06-29 17:50:54 +00:00
|
|
|
wrapLocation : Point -> Point -> Point
|
|
|
|
wrapLocation maxLocation location =
|
|
|
|
let
|
|
|
|
( x, y ) =
|
|
|
|
location
|
|
|
|
|
|
|
|
( maxX, maxY ) =
|
|
|
|
maxLocation
|
|
|
|
in
|
|
|
|
( (fmod x maxX), (fmod y maxY) )
|
|
|
|
|
|
|
|
|
2017-06-27 22:25:06 +00:00
|
|
|
distanceFromSpeed : Float -> Float -> Float
|
|
|
|
distanceFromSpeed pixPerSec millis =
|
|
|
|
pixPerSec * millis / 1000
|
|
|
|
|
|
|
|
|
|
|
|
fmod : Float -> Float -> Float
|
|
|
|
fmod lh rh =
|
|
|
|
lh - (toFloat (floor (lh / rh)) * rh)
|
2017-06-28 21:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
rectToRectCollision : ( Point, Point ) -> ( Point, Point ) -> Bool
|
|
|
|
rectToRectCollision ( ( ax1, ay1 ), ( ax2, ay2 ) ) ( ( bx1, by1 ), ( bx2, by2 ) ) =
|
|
|
|
ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1
|