00:00
00:00
Newgrounds Background Image Theme

picapip just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss: Spiral Generator

2,022 Views | 13 Replies
New Topic Respond to this Topic

Foss: Spiral Generator 2005-07-27 09:46:42


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

Response to Foss: Spiral Generator 2005-07-27 09:49:53


http://img289.images..?image=spiral4jc.swf

^^^ SWF

Forgot to mention BASED OFF OF SOMETHING I MAGE ON MY TI-83 CALCULATOR but much faster.

Response to Foss: Spiral Generator 2005-07-27 09:50:00


Good code but not usefull at all = )


BBS Signature

Response to Foss: Spiral Generator 2005-07-27 09:51:11


At 7/27/05 09:50 AM, -Toast- wrote: Good code but not usefull at all = )

it has plenty of uses! You can print your spiral and mesmorize friends with it!

Response to Foss: Spiral Generator 2005-07-27 09:54:36


At 7/27/05 09:51 AM, Glaiel_Gamer wrote:
At 7/27/05 09:50 AM, -Toast- wrote: Good code but not usefull at all = )
it has plenty of uses! You can print your spiral and mesmorize friends with it!

Hmm.. But no one is going to use it for a flash game.
I wouldn't waste ink anyway = )


BBS Signature

Response to Foss: Spiral Generator 2005-07-27 09:56:10


Also, can someone help me isolate the freezing problem with 99 speed and 181 degrees? Cause 181 degrees works fine on a lower speed and 99 speed works fine on other degrees.

Also, never make the speed value go over 99, it will crash.

Response to Foss: Spiral Generator 2005-07-27 09:58:41


At 7/27/05 09:54 AM, -Toast- wrote:
At 7/27/05 09:51 AM, Glaiel_Gamer wrote:
At 7/27/05 09:50 AM, -Toast- wrote: Good code but not usefull at all = )
it has plenty of uses! You can print your spiral and mesmorize friends with it!
Hmm.. But no one is going to use it for a flash game.
I wouldn't waste ink anyway = )

It's a nifty pre-loader thing.
I used an older version of it in a flash game tho, check gg's ultimate arcade.

And since the spiral itself is in a movie clip, you can rotate it and use it as a mesmorizing background for a game.

Response to Foss: Spiral Generator 2005-07-27 09:59:31


why can't you execute "frame" once when it's clicked instead of constantly?

Response to Foss: Spiral Generator 2005-07-27 10:02:25


At 7/27/05 09:59 AM, Inglor wrote: why can't you execute "frame" once when it's clicked instead of constantly?

cause. I didn't make it that way.

Response to Foss: Spiral Generator 2005-07-27 10:09:46


At 7/27/05 10:02 AM, GGAntiPostLimit wrote:
At 7/27/05 09:59 AM, Inglor wrote: why can't you execute "frame" once when it's clicked instead of constantly?
cause. I didn't make it that way.

so please explain that to me, and please don't use that account unless you MUST or the administration will execute me.

Response to Foss: Spiral Generator 2005-07-27 10:14:53


At 7/27/05 10:09 AM, Inglor wrote:
At 7/27/05 10:02 AM, GGAntiPostLimit wrote:
At 7/27/05 09:59 AM, Inglor wrote: why can't you execute "frame" once when it's clicked instead of constantly?
cause. I didn't make it that way.
so please explain that to me, and please don't use that account unless you MUST or the administration will execute me.

Well, 1st I kinda like it that way because I want them to see that they can't use letters and punctuation or it resets them to default.

Second, I made it that way and I don't feel like changing it.

Response to Foss: Spiral Generator 2005-07-27 10:57:20


what is Foss?

Response to Foss: Spiral Generator 2005-07-27 10:58:24


At 7/27/05 10:57 AM, -DAZA- wrote: what is Foss?

Foss: main


Sup, bitches :)

BBS Signature

Response to Foss: Spiral Generator 2005-07-27 12:18:10


At 7/27/05 10:57 AM, -DAZA- wrote: what is Foss?

basically you get to use this whereever you want whenever you want if you give me credit.