Javascript Spiral
Drawing a spiral with the canvas and javascript
HTML
<!DOCTYPE html>
<html>
<head>
<title>archimedes spiral</title>
<style type="text/css">
canvas {border: 1px solid #000000;}
</style>
</head>
<body>
<canvas width="400" height="400" id="pageCanvas">
You do not have a canvas enabled browser
</canvas>
</body>
</html>
JavaScript
var context = document.getElementById('pageCanvas').getContext('2d');
var n = 1;
lastX = 0;
lastY = 0;
<!-- clear the drawing surface -->
context.clearRect(0,0,400,400);
context.save();
context.lineWidth = 1;
context.translate(200,200);
context.moveTo(0,0);
var radius=200;
var samples=256;
var a = 0;
var b = 3;
for(i = 0; i <= (radius/b) + radius%b; i+=((radius/b)/samples)) {
r = a + (b*i);
x = r * Math.cos(i);
y = r * Math.sin(i);
context.lineTo(x,y);
}
context.stroke();
context.restore();