Skip to content

Instantly share code, notes, and snippets.

@sunny
Created January 6, 2010 17:53
Show Gist options
  • Save sunny/270465 to your computer and use it in GitHub Desktop.
Save sunny/270465 to your computer and use it in GitHub Desktop.
// Creates a hexon in Raphael
// Example: paper.hexagon(50)
Raphael.fn.hexagon = function(radius) {
var path = ""
for (var i = 0; i <= 6; i++) {
var a = i * 60,
x = radius * Math.cos(a * Math.PI / 180),
y = radius * Math.sin(a * Math.PI / 180)
path += (i == 0 ? "M" : "L") + x + "," + y
}
path += "Z"
return this.path(path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment