Created
April 23, 2015 03:22
-
-
Save jordanluyke/809964c51eae9c27f70b to your computer and use it in GitHub Desktop.
circa 2012
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>polygons</title> | |
<script type="text/javascript"> | |
var amount; | |
var size; | |
var X; | |
var Y; | |
window.onload = draw; | |
function draw() { | |
var canvas = document.getElementById('myCanvas'); | |
canvas.width = canvas.width; //this clears previous shape | |
if (canvas.getContext) { | |
var myShape = canvas.getContext('2d'); | |
amount = document.getElementById('inputAmount').value; | |
size = document.getElementById('inputSize').value; | |
myShape.beginPath(); | |
for (var i=1;i<=amount;i++) { | |
X = Math.cos(i*2*Math.PI/amount)*size+150; | |
Y = Math.sin(i*2*Math.PI/amount)*size+50; | |
if (i==1) { | |
myShape.moveTo(X,Y); | |
} else { | |
myShape.lineTo(X,Y); | |
} | |
} | |
myShape.fill(); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<canvas id="myCanvas" width="500" height="200"> | |
Update your browser to a current one. | |
</canvas> | |
<br> | |
Amount:<input type="text" id="inputAmount" value="4" onchange="draw()"> | |
Size:<input type="text" id="inputSize" value="40" onchange="draw()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment