http://www.glaielgames.com/Spiral.fla
There's the source.
So, what does it do?
We'll look at some of the functions. Here's the entire code of the first frame.
deg = 10;
spd = 97;
alp = 100;
wid = 1;
fil = "off";
this.createEmptyMovieClip("clip", 1);
clip._x = 275;
clip._y = 200;
function frame() {
deg = Number(deg);
spd = Number(spd);
alp = Number(alp);
wid = Number(wid);
if (isNaN(deg)) {
deg = 10;
}
if (isNaN(spd)) {
spd = 97;
}
if (isNaN(alp)) {
alp = 100;
}
if (isNaN(wid)) {
wid = 1;
}
}
function generate() {
clip.clear();
angle = 0;
dist = 200;
speed = (spd/1000)+.9;
x = dist*Math.sin(angle*(Math.PI/180));
y = dist*Math.cos(angle*(Math.PI/180));
clip.moveTo(x, y);
colo = "0x"+col;
clip.lineStyle(wid, Number(colo), alp);
if (fil == "on") {
Fcolo = "0x"+Fcol;
clip.beginFill(Number(Fcolo), 100);
}
while (dist>3) {
dist *= speed;
angle += deg;
x = dist*Math.sin(angle*(Math.PI/180));
y = dist*Math.cos(angle*(Math.PI/180));
clip.lineTo(x, y);
}
if (fil == "on") {
clip.endFill();
}
}
So basically what we have here is a few variables being defined, and 2 functions. When I made this I didn't really plan on making it user-friendly, so I give the source too. There needs to be a seperate movie clip calling the frame function every frame. Just put this code on any movie clip.
onClipEvent(enterFrame){
_parent.frame()
}
Ok, now we'll look at the actuall code for making the spiral.
function generate() {
clip.clear();
//CLEARS THE MOVIE CLIP
angle = 0;
dist = 200;
speed = (spd/1000)+.9;
//DECLARES SOME VARIABLES
x = dist*Math.sin(angle*(Math.PI/180));
y = dist*Math.cos(angle*(Math.PI/180));
clip.moveTo(x, y);
//FINDS THE STARTING POINT OF THE SPIRAL AND MOVES THE DRAWING POINT THERE
colo = "0x"+col;
//CREATES A STRING FOR THE HEX COLOR CODE
clip.lineStyle(wid, Number(colo), alp);
//SETS THE LINE STYLE
if (fil == "on") {
Fcolo = "0x"+Fcol;
clip.beginFill(Number(Fcolo), 100);
}
//FILLS THE SPIRAL ONLY IF FILL IS ON
while (dist>3) { //THE WHILE MAKES THE SPIRAL STOP GENERATING AT A CERTAIN POINT
dist *= speed;
angle += deg;
// INVISIBLE LINE (EXPLAINED FARTHER DOWN)
x = dist*Math.sin(angle*(Math.PI/180));
y = dist*Math.cos(angle*(Math.PI/180));
clip.lineTo(x, y);
//DRAWS A LINE
}
if (fil == "on") {
clip.endFill();
}
//ENDS FILL
}
Ok, how does it work? Picture a line from the center of the screen to the bottom of the screen. Put a point at the end of the line (at the bottom of the screen). Now rotate that line a bit, and shrink it. Draw a line from the end of the old line to the end of the new line. Then repeate the process. Eventually it will be a small enough line that it ends the while loop. East to understand? Just look at the file. I highley suggest downloading the file, as I spiced up it with a bunch of buttons and textfields.
So that's how it works. This code alone will not replicate my spiral generator, tho. This is the main chunk of code tho.
Questions? Comments?
FOSS: Mail
www.glaielgames.com <Downloading the source uses my bandwith. Please help me support my site.
GG, Out