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-1-5

Get Adobe Flash player
by mutantleg 05 Jan 2015
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/49KW
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            
            vecConn = new Vector.<xConn>(0, false);
            vecPart = new Vector.<xPart>(0, false);
            
            var c:xConn;            var a:xPart;
            var i:int;            var num:int;            var ang:Number;
            
            num = 12;
            for (i = 0; i < num; i ++)
            {
                a = new xPart();
                a.cx = 64 + i * 32;  a.cy = 230;
                
                ang = (6.28 / num) * i;
                a.cx = Math.cos(ang) * 128 + 230;
                a.cy = Math.sin(ang) * 64 + 230;
                
                a.gx = a.cx; a.gy = a.cy;
                vecPart.push(a);
            }//nexti      
            
            num = vecPart.length;
            for (i = 0; i < num-1; i ++)
            { makeConn(vecPart[i], vecPart[i+1]);}
             makeConn(vecPart[0], vecPart[num-1]);
            
            
          stage.addEventListener(MouseEvent.MOUSE_OUT, onMup);  
          stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
          stage.addEventListener(MouseEvent.MOUSE_UP, onMup);  
          stage.addEventListener(Event.ENTER_FRAME, onEnter);  
        }//ctor

        public function makeConn(a:xPart, b:xPart):void
        {
          var conn:xConn;
          conn = new xConn();
          conn.a = a; conn.b = b;
          conn.rest = getMag(a.cx-b.cx, a.cy- b.cy)+5; 
          vecConn.push(conn);            
        }//makeconn
        
        public var vecPart:Vector.<xPart>;
        public var vecConn:Vector.<xConn>;
        
        public function onMdown(e:MouseEvent):void { mdown = true; }
        public function onMup(e:MouseEvent):void { mdown = false; }
        
        public var mdown:Boolean = false;
        
        public var wa:xPart;
        
        public function onEnter(e:Event):void
        {
          graphics.clear();
          graphics.lineStyle(2, 0);
          
          var mx:Number; var my:Number;
          mx = stage.mouseX;
          my = stage.mouseY;
          
          var ang:Number;          var mag:Number;
          var d:Number;          var pa:xPart;
          mag = 9999;        
          pa = vecPart[0];
          
          var conn:xConn; var b:xPart;
          var i:int; var num:int; var a:xPart;
          num = vecPart.length;
          for (i = 0; i < num; i++)
          {
              a = vecPart[i];
              
              a.vy += 0.1;
              
              a.vx += (a.gx-a.cx)*0.02;
              a.vy += (a.gy-a.cy)*0.02;
              
              a.vx *= 0.96;     a.vy *= 0.96;
              
              a.cx += a.vx;    a.cy += a.vy;
              
             // graphics.drawCircle(a.cx,a.cy,8);
             // graphics.drawCircle(a.gx,a.gy, 2);
              
              d = getMag(a.cx-mx,a.cy-my);
              if (d < mag)  { mag = d; pa = a; }
          }//nexti
          
          graphics.lineStyle(2,0);
          graphics.beginFill(0xFF, 0.5);
          num = vecPart.length;
          a = vecPart[0]; graphics.moveTo(a.cx,a.cy);
          for (i = 1; i < num; i++)
          {  a = vecPart[i];    graphics.lineTo(a.cx,a.cy); } 
          a = vecPart[0]; graphics.lineTo(a.cx,a.cy);         
          graphics.endFill();
          
            
          if (wa == null) { wa = pa;}  
 
         graphics.drawRect(wa.cx-8,wa.cy-8,16,16);          
           
         if (mdown == false) {wa = null; }   
         if (mdown)
         {
           
           ang = Math.atan2(my-wa.cy,mx-wa.cx);
           wa.vx += Math.cos(ang)*0.85;
           wa.vy += Math.sin(ang)*0.85;
              
           graphics.moveTo(wa.cx, wa.cy); graphics.lineTo(mx,my);   
         }//endif   
         
         
         num = vecConn.length;
         for (i = 0; i < num; i++)
         {
            conn = vecConn[i];
            a = conn.a; b = conn.b;
            graphics.moveTo(a.cx, a.cy);
            graphics.lineTo(b.cx, b.cy); 
            
            if (getMag(a.cx-b.cx,a.cy-b.cy) <= conn.rest) { continue; }
            
            ang = Math.atan2(b.cy-a.cy, b.cx-a.cx);
            
            a.vx += Math.cos(ang)*0.5;
            a.vy += Math.sin(ang)*0.5;
            b.vx += Math.cos(ang)*-0.5;
            b.vy += Math.sin(ang)*-0.5;
         }//nexti
         
         
            
            
        }//onenter
        
        public function getMag(ax:Number,ay:Number):Number { return Math.sqrt(ax*ax+ay*ay); }
        
        
    }//classend
}

internal class xPart
{
    public var cx:Number = 0;    public var cy:Number = 0;
    public var vx:Number = 0;    public var vy:Number = 0;    
    public var gx:Number = 0;    public var gy:Number = 0;
    
}//xpart

internal class xConn
{
  public var a:xPart = null;
  public var b:xPart = null;
  
  public var rest:Number = 50;
    
}//xconn