Skip to content

Instantly share code, notes, and snippets.

@TheDeadCode
Created December 8, 2015 19:27
Show Gist options
  • Save TheDeadCode/955354ce0035a1aae29e to your computer and use it in GitHub Desktop.
Save TheDeadCode/955354ce0035a1aae29e to your computer and use it in GitHub Desktop.
RaphaelJS Helper
class Path
constructor: (@startX, @startY) ->
@path = []
@string = null
@moveTo @startX, @startY
pop: ->
@path.pop()
@string = null
this
moveTo: (x, y) ->
@path.push ['M', x, y]
this
lineTo: (x, y) ->
@path.push ['L', x, y]
this
close: ->
@path.push ['Z']
this
#Alias
closePath: ->
@close()
horizontal: (x) ->
@path.push ['H', x]
this
vertical: (y) ->
@path.push ['V', y]
this
curveTo: (x1, y1, x2, y2, x, y) ->
@path.push ['C', x1, y1, x2, y2, x, y]
this
sCurveTo: (x2, y2, x, y) ->
@path.push ['S', x2, y2, x, y]
this
qCurveTo: (x1, y1, x, y) ->
@path.push ['Q', x1, y1, x, y]
this
sqCurveTo: (x, y) ->
@path.push ['T', x, y]
this
arcTo: (rx, ry, xRot, lArcFlag, sweepFlag, x, y) ->
@path.push ['A', rx, ry, xRot, lArcFlag, sweepFlag, x, y]
this
crCurveTo: (x1, y1, x, y) ->
arr = [x1, y1]
arr.push x if x?
arr.push y if y?
this
compile: ->
@string = ""
for arg in @path
arTmp = arg.slice()
@string += arTmp[0]
[].shift.apply arTmp, []
@string += [].join.apply arTmp, [',']
@string
toString: ->
string if string?
@compile()
get: ->
@toString()
draw: (paper) ->
paper.path @get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment