In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Gravity

Get Adobe Flash player
by bradsedito 26 Jun 2012
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wNmJ
 */


package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.MovieClip;
    import flash.geom.Vector3D
    
    
    public class Gravity extends Sprite 
    {
        private var particles:Vector.<MovieClip>
        private var hole:Vector3D


        public function Gravity() 
        {
           particles = new <MovieClip>[]
          
           for(var i:uint = 0; i < 600; i++) 
           {
               addOne()
           }
           
           hole = new Vector3D()
           addEventListener( "enterFrame",frame )
           addEventListener( "enterFrame",real_time )
        }
        
        private function real_time( event:Event ):void
        {
            
        }

        
        private function frame(e:Event):void 
        {
            for(var i:int = particles.length - 1; i >= 0; i--) 
            {
                var sp:MovieClip = particles[i]
                var d:Vector3D
                sp.pos = sp.pos.add(sp.vec)
                sp.x = 400*sp.pos.x/sp.pos.z
                sp.y = 400*sp.pos.y/sp.pos.z
                sp.z = 400*sp.pos.z/sp.pos.z
                //sp.scaleX = 1/sp.pos.z
                //sp.scaleY = 1/sp.pos.z
                sp.visible = sp.pos.z > 0.001
                addEventListener( Event.ENTER_FRAME,singularity )
                function singularity( ):void               
                {        
                    sp.x[i]  +=  stage.mouseX  //stage.stageWidth  /2
                    sp.y[i]  +=  stage.mouseY  //stage.stageHeight /2
                    //sp.z[i]  +=  0
                }

            }
        }
        
        
        private function addOne():void {
            var sp:MovieClip = new MovieClip()
            sp.graphics.beginFill(0)
            sp.graphics.drawCircle(0,0,5)
            sp.graphics.endFill()
            sp.pos = new Vector3D(Math.random(), Math.random(), Math.random())
            sp.vec = new Vector3D(Math.random()/100-1/200, Math.random()/100-1/200, Math.random()/100-1/200)
            addChild(sp)
            particles.push(sp)
        }
    }
}