Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: Re: FLASH: starfield using arctangent available!
From: Barry Swan
Date: Tue, 4 Jul 2000 23:36:06 +0100

OK, well, strangely enough I don't use Flash, I'm only on this list because
I believe my boss will ask me to learn it soon enough and it helps to keep
up with technology :)

So the specifics of the actionscript are lost on me, although i can gather a
certain amount of stuff from the maths.

So you'll have to bear with me. I am assuming that Flash can do several
things - It can generate random numbers, you can position/scale a symbol 'at
will', and that you have some means of storing some variables for each
symbol. I'd use a list in Director, not sure what the work-around is in
Flash, but you've probably already done that.

Ok, for each star you need to store it's X, Y and Z coordinates. Generate X
and Y within a certain amount randomly and set the Z to be far away
(errr.... say 1000? It's a random figure plucked out of the air!).

Then for each frame you subract from the Z coordinate (ie it's getting
nearer to you), then you calculate it's screen X and Y coordinates with the
simple eqaution:

screenX = x/z
screenY = y/z

You'll probably want to add half the screen size to make it centered, but
that's about it.
Only thing you have to watch out for is divide by zero errors. Just check Z
coordinates, and if too close to zero then reset it back to the far plane.

Barry
gerbilattheburrow [dot] co [dot] uk


>
>>Without looking at the FLA (not at a computer with Flash :( can I ask what
>>you are using the arctan() for?
>>Perspective effects are a simple z divide. Or am I missing something?
>>
>>Barry
>>gerbilattheburrow [dot] co [dot] uk
>
>
>Hi Barry,
>
>I don't know what z divide means. If you could explain I would appreciate
>very much. Frankly, I know very little math and am trying to learn as much
>as I can.
>
>I'd be glad to know there was a simpler solution than arctan to solve my
>problem. I wrote to the list last week asking about this and no one
>offered a better way! As convoluted as this became, I know there must be
>and all you math jocks were just holdin out on me dammit.
>
>Anyway, I started to go into the long explanation of what I was doing and
>thought maybe it would be clearer to just include the code....
>
>Set Variable: "count" = count + 1
>Set Variable: "j" = 0
>Loop While (j < 10)
>Set Variable: "p" = count &j
>Duplicate Movie Clip ("/star", "star" &p, p)
>Set Variable: "locationX" = Random (100) + 350
>Set Variable: "locationY" = Random (100) + 150
>Set Variable: "scale" = Random (30) + 30
>Set Property ("/star" &p, X Position) = locationX
>Set Property ("/star" &p, Y Position) = locationY
>Set Property ("/star" &p, X Scale) = scale
>Set Property ("/star" &p, Y Scale) = scale
>Comment: Determine Center of Screen
>Set Variable: "x" = (locationY - 200) / (locationX - 400)
>Comment: **************************
>Comment: Begin Arctan Function
>If (x > -1.0 and x < 1.0)
>Set Variable: "arctan" = x-(x*x*x/3)+(x*x*x*x*x/5)-(x*x*x*x*x*x*x/7)
>Set Variable: "output" = (arctan * 180) / 3.1416
>Else If (x >= 1)
>Set Variable: "arctan" = (3.1416 / 2) - (1 / x) + (1 / ( 3 * (x*x*x))) - (1
>/ (5 * (x*x*x*x*x))) + (1 / (7 * (x*x*x*x*x*x*x)))
>Set Variable: "output" = (arctan * 180) / 3.1416
>Else If (x <= -1)
>Set Variable: "arctan" = - (3.1416 / 2) - (1 / x) + (1 / ( 3 * (x*x*x))) -
>(1 / (5 * (x*x*x*x*x))) + (1 / (7 * (x*x*x*x*x*x*x)))
>Set Variable: "output" = (arctan * 180) / 3.1416
>End If
>Comment: End Arctan Function
>Comment: *************************
>Comment: Output is between -90 and 90 degrees. The following compensates
>for this. Anything left of center we add 180 degrees.
>If (locationX < 400)
>Set Property ("/star" &p, Rotation) = output +180
>Else
>Set Property ("/star" &p, Rotation) = output
>End If
>Set Variable: "j" = j + 1
>End Loop
>
>Basically just telling a randomly placed MC to find the center of the
>screen and rotate directly away from it. I tried turning it inwards which
>was cool and also used the mouse coordinates as the center and that was
>pretty cool too.
>
>Again, if you know a better way I would be grateful as I really would love
>to use this in a clients animation I'm currently working on and as it
>stands now it is probably too processor intensive.
>
>Muchos Gracias,
>Kurt
>http://www.dommermuth-1.com
>
>
>flasher is generously supported by...
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> flashforward2000 and the Flash(tm) Film Festival
> July 24-26, 2000, NEW YORK CITY, Hammerstein Ballroom
> www.flashforward2000.com
> Produced by United Digital Artists and lynda.com
> Sponsored by Macromedia, Adobe Systems, Fusion, Inc, AtomFilms,
> shockwave.com and Electric Rain.
> 1.877.4.FLASH.4 or (1.805.640.6679 outside the US and Canada)
> Register before June 30 and save $200!!-- www.flashforward2000.com
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>To unsubscribe or change your list settings go to
>http://www.chinwag.com/flasher or email helpatchinwag [dot] com
>


flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash(tm) Film Festival
July 24-26, 2000, NEW YORK CITY, Hammerstein Ballroom
www.flashforward2000.com
Produced by United Digital Artists and lynda.com
Sponsored by Macromedia, Adobe Systems, Fusion, Inc, AtomFilms,
shockwave.com and Electric Rain.
1.877.4.FLASH.4 or (1.805.640.6679 outside the US and Canada)
Register before June 30 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


Replies
  FLASH: Problem with variables parameters, Leonardo J. Creo

[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]