Skip to content

Instantly share code, notes, and snippets.

@cryptoquick
Last active December 17, 2015 17:38
Show Gist options
  • Save cryptoquick/5647045 to your computer and use it in GitHub Desktop.
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.
Display the source blob
Display the rendered blob
Raw
<?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