Last active
December 17, 2015 17:38
-
-
Save cryptoquick/5647045 to your computer and use it in GitHub Desktop.
This is a pentagon, but it could be virtually any regular polygon of any number of sides and of any chosen radius.
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
<?xml version="1.0"?> | |
<svg xmlns="http://www.w3.org/2000/svg" width="300" version="1.1" height="300" baseProfile="tiny" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<path id="pentagon"></path> | |
<script type="application/ecmascript"><![CDATA[ | |
var sides = 5, | |
radius = 100, | |
first = sides % 2 === 0 ? Math.PI / sides : 3 * Math.PI / 2, | |
mult = 2 * Math.PI / sides, | |
points = ['M']; | |
for (var i = 0; i < sides; ++i) { | |
points.push(Math.round(radius * Math.cos(first + i * mult) + radius) + ',' + Math.round(radius * Math.sin(first + i * mult) + radius)); | |
} | |
points.push('z'); | |
document.getElementById('pentagon').setAttribute('d', points.join(' ')); | |
]]></script> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment