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

forked from: nattou

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






package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    
    
    public class FlashTest extends Sprite 
    {
        public  var SW:Number = new Number( stage.stageWidth  );
        public  var SH:Number = new Number( stage.stageHeight );
        public  var SD:Number = new Number( 1000               );
        public  var Particles:Array;
        public  var ball:Ball;
        public  var numParticle:int = 3;
        public  var minDist:Number = 10;
        public  var spring:Number = 0.000;
        public  var size:int;
        
        public function FlashTest() 
        {
           init();
        }
        
        public function init():void
        {
                Particles =[];
                for (var i:int = 0; i <numParticle; i++){
                    Particles.push(new Ball(5));
                    size = Math.random()* 3 + 2;
                    
                    Particles[i].scaleY = Particles[i].scaleX = size;
                    Particles[i].mass = size;
                    Particles[i].x = Math.random() * SW;
                    Particles[i].y = Math.random() * SH;
                    Particles[i].z = Math.random() * SD;
                    Particles[i].vx = Math.random()* 6 - 3;
                    Particles[i].vy = Math.random()* 6 - 3;
                    Particles[i].vz = Math.random()* 6 - 3;
                    addChild(Particles[i]);
                }
                
                addEventListener(Event.ENTER_FRAME, onenterframe);
        }
        
        public function onenterframe(e:Event):void{
                for (var i:int = 0;i < numParticle;i++){
                    var p:Ball = Particles[i];
                    p.x += p.vx;
                    p.y += p.vy;
                    p.z += p.vz;
                    if (p.x >stage.stageWidth + p.width/2){
                        p.x =0;
                    } else if (p.x < -p.width){
                         p.x = stage.stageWidth;    
                    }
                    if (p.y > stage.stageHeight + p.height/2){
                        p.y = 0;
                    } else if (p.y < -p.height) {
                        p.y = stage.stageHeight;    
                    }
                }
                
                for (i = 0; i < numParticle;i++){
                    var pA:Ball = Particles[i];
                    for (var j:int = 0;j < numParticle - 1;j++){
                        var pB:Ball = Particles[j];
//                        Spring(pA,pB);
                    }
                }
            
                graphics.clear();
                particleLine();           
        }
        
        /*public function Spring(pA:Ball,pB:Ball):void
        {
                var dx:Number = pB.x - pA.x;
                var dy:Number = pB.y - pA.y;
                var dz:Number = pB.z - pA.z;
                var dist:Number = Math.sqrt( dx*dx + dy*dy + dz*dz);
                if (dist < minDist)
                {
                    var ax:Number = dx * spring;
                    var ay:Number = dy * spring;
                    var az:Number = dz * spring; 
                                   
                    pA.vx += ax / pA.mass;
                    pA.vy += ay / pA.mass;
                    pA.vz += az / pA.mass;
                    
                    pB.vx -= ax / pB.mass;
                    pB.vy -= ay / pB.mass;
                    pB.vz -= az / pB.mass;               }
        }*/
        
        public function particleLine():void
        {
                for (var i:int = 0;i < numParticle -1; i++)
                {
                     
                        graphics.lineStyle(1,0xaaaaaa);
                        graphics.lineTo(Particles[i], Particles[i].y);
                        graphics.moveTo(Particles[i].x, Particles[i].y);
                        //graphics.moveTo(Particles[i].z, Particles[i].z);
                }
        }
        
    }
}


import flash.display.Sprite;
class Ball extends Sprite {
    
    public var mass:int;
    public var vx  :Number;
    public var vy  :Number;
    public var vz  :Number;
    public var regX:Number;
    public var regY:Number;
    public var regZ:Number;
    
    public function Ball (r:Number = 5,color:uint = 0x000000)
    {
        graphics.lineStyle(0);
        graphics.beginFill(color);
        graphics.drawCircle( r/2,r/2,r );
        graphics.endFill();        
        
    }            
}