Skip to content

Commit

Permalink
Added rotationAtFraction and ofsetted angle animation with start
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Feb 1, 2018
1 parent e1711bd commit 8cc82e7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions framer/SVGPath.coffee
Expand Up @@ -108,6 +108,15 @@ class exports.SVGPath extends SVGBaseLayer
pointAtFraction: (fraction) ->
@_path.getPointAtLength(@length * fraction)

rotationAtFraction: (fraction, delta = 0.01) ->
if delta <= 0
delta = 0.01
fromPoint = @pointAtFraction(Math.max(fraction - delta, 0))
toPoint = @pointAtFraction(Math.min(fraction + delta, 1))
angle = Math.atan2(fromPoint.y - toPoint.y, fromPoint.x - toPoint.x) * 180 / Math.PI - 90
return angle


convertStartToLayer: (layer) ->
@convertPointToLayer(@start, layer)

Expand All @@ -125,9 +134,7 @@ class exports.SVGPath extends SVGBaseLayer
return (key, value) =>
target[key] = offset + @pointAtFraction(value).y
when "angle"
offset -= @rotationAtFraction(0)
return (key, value, delta = 0) =>
return if delta is 0
fromPoint = @pointAtFraction(Math.max(value - delta, 0))
toPoint = @pointAtFraction(Math.min(value + delta, 1))
angle = Math.atan2(fromPoint.y - toPoint.y, fromPoint.x - toPoint.x) * 180 / Math.PI - 90
target[key] = angle
target[key] = offset + @rotationAtFraction(value, delta)

0 comments on commit 8cc82e7

Please sign in to comment.