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

flash on 2015-11-16

Get Adobe Flash player
by mutantleg 15 Nov 2015
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/M1UX
 */

package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
       
           vecAct = new Vector.<xBall>(0, false);
       
           var i:int; var a:xBall;
           for (i=0;i<64;i+=1)
           {
             a = new xBall();
              a.cx = Math.random()*430;
              a.cy = Math.random()*430; 
              vecAct.push(a);
              a.rad = 5+Math.random()*32; 
           }//nexti
       
           stage.addEventListener(Event.ENTER_FRAME, onEnter);     
        }//ctor
        
        public var vecAct:Vector.<xBall>;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            var i:int; var num:int; var a:xBall;
            num = vecAct.length;
            for (i=0;i<num;i+=1)
            {
              a = vecAct[i];
              
              a.vy += 0.3;
              
              a.vx *= 0.99;
              a.vy *= 0.99;
              
              if (a.cy > 465-a.rad && a.vy>0) { a.vy *= -0.5; a.cy=465-a.rad; }
              if (a.cx < a.rad && a.vx<0) { a.vx *= -0.5; a.cx=a.rad; }
              if (a.cx > 465-a.rad && a.vx>0) { a.vx *= -0.5; a.cx=465-a.rad;}
              
              checkCol(a);
              
              a.cx += a.vx;
              a.cy += a.vy;
              
              graphics.beginFill(0x808080,1);  
               graphics.drawCircle(a.cx,a.cy, a.rad);  
              graphics.endFill();  
                
            }//nexti
            
        }//oenenter
        
        
        public function getMag(ax:Number,ay:Number):Number
        { return Math.sqrt(ax*ax+ay*ay); }
        
        public function checkCol(m:xBall):void
        {
            
            var i:int; var num:int; var a:xBall;
            var dot:Number; var nx:Number; var ny:Number;
            var ta:Number; var d:Number;
            num = vecAct.length;
            for (i=0;i<num;i+=1)
            {
              a = vecAct[i];
              if (a == m) { continue; } 
              d = getMag(a.cx-m.cx, a.cy-m.cy);
              if (d > a.rad+m.rad) { continue; } 
            
              ta = Math.atan2(a.cy-m.cy, a.cx-m.cx);
               m.cx += Math.cos(ta) * (d - (m.rad+a.rad))*0.25;
               m.cy += Math.sin(ta) * (d - (m.rad+a.rad))*0.25; 
              nx = Math.cos(ta);  ny = Math.sin(ta);
              
              dot = nx*m.vx + ny*m.vy;
               
              if (dot > 0)
              {
               m.vx -= nx * dot;
               m.vy -= ny * dot;
              }//endif    
            }//nexti
            
        }//checkkcol
        
        
    }
}

internal class xBall
{
  public var cx:Number = 0;
  public var cy:Number = 0;  
  public var vx:Number = 0;
  public var vy:Number = 0;  
  public var rad:Number = 16;  
    
}//xball