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-26

Get Adobe Flash player
by mutantleg 26 Jan 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/kXfI
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
         
          makePoint();
          stage.addEventListener(MouseEvent.CLICK, onClick);    
        }//ctor
        
        public function onClick(e:Event):void { makePoint(); }
        
        public var vecPnt:Vector.<xPoint>;
        
        public function makePoint():void
        {
            graphics.clear();
            graphics.lineStyle(2,0);
            var a:xPoint;    var i:int;
            var ax:Number; var ay:Number;
            vecPnt = new Vector.<xPoint>(0,false);
            ax = 0; ay = 0;
            for (i  = 0; i < 32; i++)
            {
               a = new xPoint();
               a.cx = 230 + (Math.random()-0.5)*280;
               a.cy = 230 + (Math.random()-0.5)*280;
               vecPnt.push(a);
               graphics.drawCircle(a.cx,a.cy, 8); 
               ax += a.cx; ay += a.cy;
            }//nexti
            ax /= vecPnt.length;
            ay /= vecPnt.length;
            
            graphics.drawCircle(ax,ay, 16);

            graphics.lineStyle(4, 0);
            var ang:Number; var prev:xPoint;
             var first:xPoint = null;
            graphics.beginFill(0xFF, 0.5);
            for (ang = 0; ang < 6.14; ang+=0.2)
            {
              //a = getFar(vecPnt, 230,230, ang);
              a = getFar(vecPnt, ax, ay, ang);
              if (a == null) { continue; }
              if (a == prev) { continue; }
              prev = a;
              if (first == null) { first= a; graphics.moveTo(a.cx,a.cy); continue; }
         
              //graphics.drawCircle(a.cx,a.cy,8);
              graphics.lineTo(a.cx,a.cy);
            //   graphics.curveTo(a.cx,a.cy, prev.cx+32, prev.cy+32); 
            }//nextang
            graphics.lineTo(first.cx,first.cy);
            graphics.endFill();
            
        }//makepnt

        public function getFar(vec:Vector.<xPoint>, ax:Number,ay:Number, ang:Number):xPoint
        {
          var nx:Number; var ny:Number;         var i:int; var num:int;
          var a:xPoint; var d:Number;          var ret:xPoint; var rd:Number;
          var ta:Number;
          rd = -999;
          //rd = 999;
          nx = Math.cos(ang); ny = Math.sin(ang);
          
          //graphics.moveTo(ax,ay);
          //graphics.lineTo(ax+nx*32,ay+ny*32);
          
          num = vec.length;
          for (i = 0; i < num; i++)
          {    
            a = vec[i]; 
            d = (a.cx - ax) * nx + (a.cy-ay) * ny;
            //if (d < 0) { continue; }
            ta = Math.atan2(ay-a.cy, ax-a.cx);
            if (angDiff(ang, ta) > 0.2) { continue; }
            
            if (d < rd) { continue; }
            //if (d > rd) { continue; }
            rd = d;
            ret = a;
          }//nexti           
          return ret; 
        }//getfar
       
       public static function angDiff(a:Number, b:Number):Number
       { a -= b;  if (a > 3.14) { a -= 6.28; }   if (a < -3.14) { a += 6.28;}  return a; }
 
        

        
        
    }//classend
}

internal class xPoint
{
  public var cx:Number=0, cy:Number=0;   
}