
Spirala Archimedesa
Krzywa określona przez równanie parametryczne:
x=aφcosφ
y=aφsinφ
Listing
var spiralaArchimedesa = function(dlugosc, ciasnosc, liczbaPunktow, strokeStyle) {
ctx.save();
ctx.beginPath();
ctx.strokeStyle = strokeStyle;
ctx.translate(w / 2, h / 2);
// ctx.scale(1, -1);
var x1 = 0;
var y1 = 0;
var x2;
var y2;
for ( var i = 0; i < liczbaPunktow; i++) {
var t = i * dlugosc * Math.PI / liczbaPunktow;
x2 = ciasnosc * t * Math.cos(t);
y2 = ciasnosc * t * Math.sin(t);
ctx.moveTo(Math.floor(x1), Math.floor(y1));
ctx.lineTo(Math.floor(x2), Math.floor(y2));
x1 = x2;
y1 = y2;
}
ctx.stroke();
ctx.restore();
};
var cv = document.getElementById("canvas");
var ctx = cv.getContext("2d");
var w = cv.width;
var h = cv.height;
spiralaArchimedesa(15, 2, 2000, "red");
