Skip to content

Instantly share code, notes, and snippets.

@jarek-foksa
Created February 3, 2014 06:21
Show Gist options
  • Save jarek-foksa/8779585 to your computer and use it in GitHub Desktop.
Save jarek-foksa/8779585 to your computer and use it in GitHub Desktop.
# http://svg-whiz.com/svg/starPrimative.svg
drawNGon: (cx, cy, r, rCorner, arms, shift = 0) ->
polyPoints = ''
if arms in [1,3,5,7,9]
orient = 'point'
else
orient = 'edge'
for s in [0..arms]
angle = 2.0 * pi * (s / arms)
if orient == 'point'
angle -= pi/2
else
angle = (angle + (pi/arms)) - (pi/2)
x = (r * cos(angle)) + cx
y = (r * sin(angle)) + cy
polyPoints += x + ',' + y + ' '
$ngon = svg 'polygon', canvas.$drawing
$ngon.setAttributeNS null, 'points', polyPoints
$ngon.setAttributeNS null, 'fill', 'blue'
$ngon.setAttributeNS(null, 'stroke', 'red')
$ngon.setAttributeNS(null, 'stroke-width', '2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment