// Spiral Maker
// Created by Brian Baker, comharsa@clara.net
// March 2000
//
// Creates a pseudo-spiral based on semicircles.
// Once drawn change the stroke to whatever you want.
// get details of spiral required
var userInfo = prompt ("Please enter two numbers, separated by a comma (eg 5, 20).\nThe first is the number of turns needed, and the second is the distance in pixels between each turn. Neither can be zero.\nNote: large numbers of turns can take a long time to process.");
var spirInfo = userInfo.split(",",2);
// check info useable
if (isNaN(spirInfo[0]) == true || isNaN(spirInfo[1]) == true || spirInfo[0] == 0 || spirInfo[1] == 0)
{
// inform user of error
alert ("The entry did not consist of two useable numbers. Please try again.");
}
else
{
// get centre of document
var docWidth = fw.getDocumentDOM().width;
var docHeight = fw.getDocumentDOM().height;
// draw centre point
fw.getDocumentDOM().addNewSinglePointPath({x:docWidth/2, y:(docHeight/2)+(spirInfo[1]/2)}, {x:docWidth/2, y:docHeight/2},
{x:docWidth/2, y:(docHeight)/2-(spirInfo[1]/2)}, true);
// draw spiral
var i = 1;
for (var j = 1; j <= spirInfo[0] ; j++)
{
fw.getDocumentDOM().appendPointToPath(0, i, {x:(docWidth/2)-(spirInfo[1]/2), y:(docHeight/2)-(((2*j)-1)*(spirInfo[1]/2))},
{x:(docWidth/2)-(spirInfo[1]/2), y:(docHeight/2)-(((2*j)-1)*(spirInfo[1]/2))}, {x:(docWidth/2)-(spirInfo[1]/2), y:(docHeight/2)-(((2*j)-1)*(spirInfo[1]/2))});
i++;
fw.getDocumentDOM().appendPointToPath(0, i, {x:(docWidth/2)-j*spirInfo[1], y:(docHeight/2)-(((2*j)-1)*(spirInfo[1]/2))},
{x:(docWidth/2)-j*spirInfo[1], y:(docHeight/2)}, {x:(docWidth/2)-j*spirInfo[1], y:(docHeight/2)+j*spirInfo[1]});
i++;
fw.getDocumentDOM().appendPointToPath(0, i, {x:docWidth/2, y:(docHeight/2)+(j*spirInfo[1])}, {x:docWidth/2, y:(docHeight/2)+(j*spirInfo[1])}, {x:docWidth/2, y:(docHeight/2)+(j*spirInfo[1])});
i++;
fw.getDocumentDOM().appendPointToPath(0, i, {x:(docWidth/2)+(j*spirInfo[1]), y:(docHeight/2)+(j*spirInfo[1])},
{x:(docWidth/2)+(j*spirInfo[1]), y:(docHeight/2)}, {x:(docWidth/2)+(j*spirInfo[1]), y:(docHeight/2)-((2*j+1)*(spirInfo[1]/2))});
i++;
}
}
|