--This is required in the frame before the frame that you "go to the frame" on exitframe. Say that ten times fast.

on exitFrame

set the actorlist = []
repeat with i = 1 to 40
set the loch of sprite i= -300
end repeat
UPDATESTAGE

repeat with i = 1 to 40
puppetsprite i, false
end repeat

set the stagecolor to 255

--this right here, births all of the orbitals
repeat with i = 1 to random(40)
new(script "Orbital Class", i)
end repeat
end

--this is a new movie script titled "ORBITAL CLASS"

--SCRIPT ORBITAL CLASS

property myType
property mySprite
property myRadius
property myAngle
property MyFactor
property myIncrement

on new me,channelnum
--this adds the child object to the actorlist allowing the use of the stepframe handler
add the actorlist, me
--this inits the speed of the balls orbit
set myIncrement=random(30)*.001559876
--this determines whether the orbit is normal or retrograde
set z =random(2)
if Z > 1 then set myIncrement=myIncrement*-1
--this assigns mysprite a channel number
set mySprite=channelnum
puppetSprite mySprite, TRUE
set the stretch of sprite mySprite to true

set the loch of sprite mysprite = -400
set myType=#Orbital
--I don't remember what this does
set myRadius=3.35*channelnum
--this inits a starting angle
set myAngle=(random(6)/3.0)*pi()
set MyFactor = 1.0001
end new

on stepFrame me
orbit me
move me
end stepFrame

on move me
--this adjusts the angle by the speed of the ball
set myAngle=myAngle+myIncrement

if mysprite > 2 then
--(mysprite - 1) is the ball in the channel before the current ball
set tempH= the loch of sprite (mysprite-1)
set tempV= the locV of sprite (mysprite-1)
else
--160 is the center of the stage
set tempH= 160.00
set tempV=160.00
end if
--this plots the x,y coord where the ball needs to go next based on a
--centerpoint, an angle and a radius
set the locH of sprite mySprite to tempH+cos(myAngle)*myRadius
set the locV of sprite mySprite to tempV+sin(myAngle)*myRadius

--this scales the sprites based on locv, this part comes from England
--courtesy of Nischal Shah
set scaleFactor to (((the locV of sprite mySprite) - 50) * 0.85 / 160) + .25
set the width of sprite mySprite to 20 * scaleFactor
set the height of sprite mySprite to 20 * scaleFactor
end move

on orbit me
--this script changes the radius of the orbit
--you may want to omit this part for your application
set myRadius=myRadius*MyFactor

if myRadius > 160-mysprite*10 then
set MyFactor = 0.9999
end if

if myRadius < mysprite*10 then
set MyFactor = 1.0001
end if
end orbit