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

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

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {

            graphics.clear();
            graphics.lineStyle(2, 0);
 
           
           var m:xNode;
           m = new xNode();
           m.cx=0;m.cy=0;
           m.cw=430;m.ch=410; 
            
            m.makeChild();
            
           var i:int; var a:xVert;
           for (i=0;i<32;i+=1)
           {
             a = new xVert;
                a.cx = Math.random()*430;
                a.cy = Math.random()*430;
             graphics.drawCircle(a.cx,a.cy, 4); 
            m.addVert(a);               
           }//nexti 

            m.calcRect();           
           m.draw(graphics);
            
        }//ctor
    }//classend
}
import flash.display.Graphics;

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

internal class xNode
{
  public var cx:Number = 0;
  public var cy:Number = 0;
  public var cw:Number = 0;
  public var ch:Number = 0;  
    
  public var cha:xNode = null;
  public var chb:xNode = null;  
  public var vecVert:Vector.<xVert>= new Vector.<xVert>(0, false);
  public var depth:int = 0;
  public var col:uint = Math.random()*0xFFffFFff;
 
  public function isIn(a:xVert):Boolean
  { if (a.cx>cx+cw||a.cx<cx||a.cy>cy+ch||a.cy<cy){return false;}return true;  }
 
  public function addVert(a:xVert):Boolean
  {
    if(isIn(a)==false) { return false; }
    if (depth >= 4) { vecVert.push(a); return true; }  
      
    if (cha == null) { makeChild(); }  
     
    if (cha.addVert(a)) { return true; }
    else { return chb.addVert(a); }  
  }//addvert 
     
  public function makeChild():void
  {
      var m:int;
     var aw:Number; var ah:Number;
     aw = cw*0.5; ah =ch*0.5;
      
      cha = new xNode();
      cha.cx=cx; cha.cy=cy;
      cha.cw=aw;   cha.ch=ch;
      cha.depth = depth+1;

   
      chb = new xNode();
      chb.depth = depth+1;
     
     if (cw > ch)
     {    
      chb.cx=cx+aw; chb.cy=cy;
      chb.cw= aw; chb.ch=ch; 
     } else
     {cha.ch=ah; cha.cw=cw;
      chb.cx=cx; chb.cy=cy+ah;
      chb.cw= cw; chb.ch=ah;    
     }//endif
     
  }//makechild   

  public function calcRect():void
  {
    if (cha != null)
    { cha.calcRect(); chb.calcRect(); 
      cx = Math.min(cha.cx, chb.cx);
      cy = Math.min(cha.cy, chb.cy);
      aw = Math.max(cha.cx+cha.cw, chb.cx+chb.cw);
      cw = aw-cx;
      aw = Math.max(cha.cy+cha.ch, chb.cy+chb.ch);
      ch = aw-cy;
      return;
    }//calcrect
    var ax:Number; var ay:Number; var aw:Number; var ah:Number;    
    var i:int; var num:int; var a:xVert;
    num = vecVert.length;
    ax=999;ay=999;aw=-999;ah=-999;
    for (i=0;i<num;i+=1)
    {
      a = vecVert[i];
      if (a.cx<ax) { ax = a.cx; }
      if (a.cy<ay) { ay = a.cy; }
      if (a.cx>aw) { aw = a.cx; }
      if (a.cy>ah) { ah = a.cy; }         
    }//nexti     
    cx=ax; cy=ay;
    cw=aw-ax; ch=ah-ay;
      
  }//calcrect
    
    
  public function draw(g:Graphics):void
  {
    g.lineStyle(5-depth,0);
    g.beginFill(col,0.1);
    g.drawRect(cx,cy,cw,ch);
    g.endFill();
    var ax:Number; var ay:Number;
    var i:int; var num:int; var a:xVert;
    ax=cx+cw*0.5; ay=cy+ch*0.5;
    num = vecVert.length;
    for (i=0;i<num;i+=1)
    { a = vecVert[i];
     g.moveTo(ax,ay);
     g.lineTo(a.cx,a.cy);
     }//nexti
    //g.drawRect(ax-4,ay-4,8,8);
    //g.moveTo(cx,cy);
    //g.lineTo(cx+cw,cy+ch);
    
    if (cha==null) { return; }
     cha.draw(g);
     chb.draw(g);  
  }//drwa
      
}//xnode