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 2016-3-3

Get Adobe Flash player
by mutantleg 03 Mar 2016
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4HwG
 */

package {
    import flash.text.TextField;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            deb = new TextField();
            deb.width=320; deb.height=240;
            addChild(deb);
            
            vecLine = new Vector.<xLine>(0,false);
            var a:xLine; var t:Number; var u:Number;

                graphics.lineStyle(2,0);
               // graphics.drawCircle(230,230,128);
            
            u = 0.314;
            for (t =0;t<6.28;t+=u)
            {
               // if (t>3.14){continue;}
                
                  a = new xLine();

                a.x0 = 230 + Math.cos(t)*256;
                a.y0 = 230 +Math.sin(t)*128;
                a.x1 = 230 + Math.cos(t+u)*256;
                a.y1 = 230 +Math.sin(t+u)*128;
                
                
                var ta:Number;
                ta = Math.atan2(a.y1-a.y0,a.x1-a.x0)+1.57;
                a.nx = Math.cos(ta);
                a.ny = Math.sin(ta);
 
                 drawLine(a);               
                
               vecLine.push(a);
            }//nextt
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor

        public var deb:TextField;
        
        public var vecLine:Vector.<xLine>;
        
        public var cx:Number=230;
        public var cy:Number=230;
        public var vx:Number = 0;
        public var vy:Number = 0;
        
        public var cnx:Number = 0;
        public var cny:Number = 0;

        public var ang:Number = 0;
        
        public var gt:int = 0;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2,0);
            
            var r:Number; var d:Number;var ta:Number;      
            var a:xLine; var num:int; var i:int;
            num=vecLine.length;
            for (i=0;i<num;i+=1)
            { a= vecLine[i]; drawLine(a); }
            
            vx *=0.99; vy+=0.2;
            
            var ms:Number;
            ms =8;
            if (vx>ms){vx=ms;}else if(vx<-ms){vx=-ms;}
            if (vy>ms){vy=ms;}else if(vy<-ms){vy=-ms;}
    
    
          // vx+=1;if (vx>8){vx=8;}
            
            r=16;

            for (i=0;i<num;i+=1)
            {  a= vecLine[i]; 
               getCloseLine(cx,cy, a.x0,a.y0, a.x1,a.y1);
               d = getMag(cx-closex,cy-closey);
               if (d>r){continue;} 
               if (d==0) {continue;}
                 var nx:Number; var ny:Number; var dt:Number;
                 nx=cx-closex;ny=cy-closey;
                 nx/=d;ny/=d;
                 dt = nx*vx+ny*vy;
                 if (dt<0)
                 { vx -=nx*dt;    vy-=ny*dt; }
                 
                 cx-=nx*(d-r);  cy-=ny*(d-r);
                 
                 if ((gt & 128)==0)
                 {  vx+=-a.ny;   vy+=a.nx; }
                 else { vx+=a.ny;   vy+=-a.nx;  } 
                 
                 cnx = a.nx; cny= a.ny;
                     
                // graphics.moveTo(cx,cy);
               //  graphics.lineTo(cx+vx*4,cy+vy*4);    
                           
                ta = ((nx - vx) * ny) - ((ny - vy) * nx); 
                ang+=ta/r;
                
                //if (ny >0){  vy-=0.2; }
            
            }//nexti

            graphics.drawCircle(cx,cy, r);
            graphics.moveTo(cx,cy);
            graphics.lineTo(cx+Math.cos(ang)*r,cy+Math.sin(ang)*r); 

            graphics.moveTo(cx-cnx*16,cy-cny*16);
            graphics.lineTo(cx+cnx*32,cy+cny*32);
        

            cx+=vx;cy+=vy;
            
            deb.text="vx "+vx.toFixed(2)+"\nvy "+vy.toFixed(2)+"\n"+gt;
            
            gt+=1;
        }//onenter

        public function getMag(ax:Number, ay:Number):Number
        { return Math.sqrt(ax*ax+ay*ay); }

       public var closex:Number = 0;
       public var closey:Number = 0; 
       public function getCloseLine(px:Number, py:Number, 
         x0:Number, y0:Number, x1:Number, y1:Number):Number
       {
          var t:Number;  var ax:Number; var ay:Number;
          var bx:Number;  var by:Number;
          
          ax = px - x0;     ay = py - y0;
          bx = x1 - x0;     by = y1 - y0;
          t = (ax*bx + ay*by) / (bx*bx + by*by);
          if (t < 0) { t = 0;}    if (t > 1) { t = 1; }
          
          closex = x0 + (x1 - x0) * t;
          closey = y0 + (y1 - y0) * t;
         return t;  
       }//getclose   
       
  
        public function drawLine(a:xLine):void
        {
            var ax:Number; var ay:Number;
            graphics.moveTo(a.x0,a.y0);
            graphics.lineTo(a.x1,a.y1);
            ax = a.x0 + (a.x1-a.x0)*0.5;
            ay = a.y0 + (a.y1-a.y0)*0.5;
            graphics.moveTo(ax,ay);
            graphics.lineTo(ax+a.nx*8,ay+a.ny*8);
            
        }//drawline
        
    }//classend
}

internal class xLine
{
  public var x0:Number = 0;  
  public var y0:Number = 0;  
  public var x1:Number = 0;  
  public var y1:Number = 0;  
  public var nx:Number = 0;
  public var ny:Number = 0;   
    
}//xline