Permalink
Browse files

Add premature support for reversing a path

  • Loading branch information...
nvh committed Feb 1, 2018
1 parent 90d9896 commit e210fb118862eb6f30492fda2587f568f25b8967
Showing with 19 additions and 1 deletion.
  1. +4 −0 framer/Animation.coffee
  2. +15 −1 framer/SVGPath.coffee
View
@@ -214,6 +214,10 @@ class exports.Animation extends BaseClass
reverse: ->
# TODO: Add some tests
properties = _.clone(@_originalState)
for key, value of @properties
if SVG.isPath(value)
value.reversed = not value.reversed
properties[key] = value
options = _.clone(@options)
new Animation @layer, properties, options
View
@@ -42,7 +42,9 @@ class exports.SVGPath extends SVGBaseLayer
startLength = @strokeStart ? 0
endLength = @strokeEnd ? @length
dasharray = []
if endLength < startLength
if endLength is startLength
dasharray = [0, startLength, 0, @length - endLength]
else if endLength < startLength
gap = startLength - endLength
remaining = @length - startLength
dasharray.push(endLength)
@@ -60,6 +62,10 @@ class exports.SVGPath extends SVGBaseLayer
dasharray.push(length)
if length isnt remaining and remaining isnt 0
dasharray.push(remaining)
if @reversed
if dasharray.length % 2 is 0
dasharray.push(0)
dasharray.reverse()
@strokeDasharray = dasharray
# Custom properties
@@ -103,15 +109,23 @@ class exports.SVGPath extends SVGBaseLayer
@define "length", get: -> @_length
@define "reversed", @simpleProperty("reversed", false)
pointAtFraction: (fraction) ->
if @reversed
fraction = 1 - fraction
@_path.getPointAtLength(@length * fraction)
rotationAtFraction: (fraction, delta = 0.01) ->
if @reversed
fraction = 1 - fraction
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
if @reversed
angle = 360 - angle
return angle
start: (relativeToLayer = null) =>

0 comments on commit e210fb1

Please sign in to comment.