Last active
January 5, 2016 19:18
-
-
Save Dillie-O/4548290 to your computer and use it in GitHub Desktop.
Function to calculate points on an equidistant star.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CalculateStarPoints(centerX, centerY, arms, outerRadius, innerRadius) | |
{ | |
var results = ""; | |
var angle = Math.PI / arms; | |
for (var i = 0; i < 2 * arms; i++) | |
{ | |
// Use outer or inner radius depending on what iteration we are in. | |
var r = (i & 1) == 0 ? outerRadius : innerRadius; | |
var currX = centerX + Math.cos(i * angle) * r; | |
var currY = centerY + Math.sin(i * angle) * r; | |
// Our first time we simply append the coordinates, subsequet times | |
// we append a ", " to distinguish each coordinate pair. | |
if (i == 0) | |
{ | |
results = currX + "," + currY; | |
} | |
else | |
{ | |
results += ", " + currX + "," + currY; | |
} | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment