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

forked from: flash on 2015-10-6

Get Adobe Flash player
by mutantleg 19 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/QHWB
 */

// forked from mutantleg's flash on 2015-10-6
package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            vecRect = new Vector.<xRect>(0,false);
            var i:int; var num:int; var a:xRect;
            num = vecRaw.length;
            for (i=0;i<num;i+=4)
            {
              a = new xRect();
               a.cx = vecRaw[i];     a.cy = vecRaw[i+1];  
               a.cw = vecRaw[i+2];   a.ch = vecRaw[i+3];  
              vecRect.push(a);                      
            }//nexti
            
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            num = vecRect.length;
            for(i=0;i<num;i+=1)
            {
              a = vecRect[i];
              graphics.drawRect(a.cx,a.cy,a.cw,a.ch);
            }//nexti
            
            var k:int;
            var b:xRect;
            for (i=0;i<num;i+=1)
            {
                a = vecRect[i];
                for (k=0;k<num;k+=1)
                {
                  b = vecRect[k]; if (a==b) { continue; }
                   if (a.cx + a.cw < b.cx) { continue; }
                   if (a.cy + a.ch < b.cy) { continue; }
                   if (b.cx + b.cw < a.cx) { continue; }
                   if (b.cy + b.ch < a.cy) { continue; }

                  var ax:Number; var ay:Number;
                  var bx:Number; var by:Number;
                    ax = Math.max(a.cx, b.cx);
                    bx = Math.min(a.cx+a.cw, b.cx+b.cw);
                    ay = Math.max(a.cy, b.cy);
                    by = Math.min(a.cy+a.ch, b.cy+b.ch);
                    if (ax>=bx && ay>=by) { continue; }
                   
                   
                   // graphics.moveTo(a.cx+a.cw*0.5, a.cy+a.ch*0.5);
                    //graphics.lineTo(b.cx+b.cw*0.5, b.cy+b.ch*0.5);
                   a.vecNext.push(b);    
                }//nextk
            }//nexti
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor

        public var vecRect:Vector.<xRect>;

        public var vecRaw:Vector.<Number> = Vector.<Number>(
         [112,96,96,64,   208,112,64,128,  208,240,64,64,
          112,240,96,64,  272,240,96,64,  112,304,48,64,
          80,368,112,48,  48,48,64,144,  368,144,48,192,
          304,80,128,64,  320,16,48,64,  240,16,80,48,
          0,192,80,48,  16,240,32,64,  16,304,32,64,
          16,368,64,48,  288,304,32,80,  192,368,96,32,
          320,336,96,32,  288,160,64,64,  128,176,64,48]);
 
        public function getOver(ax:Number, ay:Number):xRect
        {
            var i:int; var num:int; var a:xRect;
            num = vecRect.length;
            for(i=0;i<num;i+=1)
            {
              a = vecRect[i];
               if (ax < a.cx) { continue; }
               if (ay < a.cy) { continue; }
               if (a.cx+a.cw < ax) { continue; }
               if (a.cy+a.ch < ay) { continue; }
              return a;
            }//nexti
            return null;            
        }//getover
        
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            var i:int; var num:int; var a:xRect;

            graphics.lineStyle(1, 0,0.5);            
            num = vecRect.length;
            for(i=0;i<num;i+=1)
            {
              a = vecRect[i];
              graphics.drawRect(a.cx,a.cy,a.cw,a.ch);
            }//nexti
            
            var ms:Number;
            ms = 128;
            gx = stage.mouseX - ms;
            gy = stage.mouseY - ms;
            gw = ms*2; gh = ms*2;
            //graphics.drawRect(gx,gy,gw,gh); 
            
            a = getOver(stage.mouseX, stage.mouseY);
            if (a == null) { return; }
            
            floodRect(a);
            
            graphics.beginFill(0, 0.5);
              graphics.drawRect(a.cx,a.cy,a.cw,a.ch);
            graphics.endFill();
        }//onenter

        
        public var gx:Number = 0;
        public var gy:Number = 0;
        public var gw:Number = 0;
        public var gh:Number = 0;

        public var curTest:int = 1;
        public var tempRect:Vector.<xRect> = new Vector.<xRect>(512, false);
        public function floodRect(m:xRect):void
        {
         var it:int;         var a:xRect;         var b:xRect;
         var num:int; var nk:int;         var i:int; var k:int;
         var vr:Vector.<xRect>;         var vk:Vector.<xRect>;
         var prev:int;
         
         vr = tempRect;
         
         curTest += 1;


         vr[0] = m; it = 1;
         m.test = curTest;
         m.prev = 0;
         
        
         i = 0;
         while (it > 0)
         {
             it -=1;
             a = vr[it];

             prev = a.prev;
             
             i+=1; if (i >= 4096) {return; } //inf loop protection
             
             graphics.beginFill(0x808080, 0.5);
              graphics.drawRect(a.cx, a.cy, a.cw, a.ch);
             graphics.endFill();
             
              
              vk = a.vecNext;
              nk = vk.length;
              for(k=0;k<nk;k+=1)
              {
                b = vk[k];
                if (b.test == curTest) { continue; }
               
                  var dir:int;
                  dir = 0;
                 
                  var ax:Number; var ay:Number;
                  var bx:Number; var by:Number;
                  
                    ax = Math.max(a.cx, b.cx);
                    bx = Math.min(a.cx+a.cw, b.cx+b.cw);
                    if (b.cy < a.cy) {  ay = a.cy; }
                    else { ay = a.cy+a.ch; }
            
                    graphics.lineStyle(4, 0xFF);
                    graphics.moveTo(ax, ay);
                    graphics.lineTo(bx, ay);
                    
                    if (bx > ax)
                    { graphics.moveTo((ax+bx)*0.5, ay); graphics.lineTo((ax+bx)*0.5,ay+((b.cy<a.cy)?8:-8)); }
                    
                    if (bx > ax) { dir = (b.cy<a.cy)?  8 : 4;  }
                                         
                    ay = Math.max(a.cy, b.cy);
                    by = Math.min(a.cy+a.ch, b.cy+b.ch);
                    if (b.cx < a.cx) {  ax = a.cx; }
                    else { ax = a.cx+a.cw; }
                    
                    graphics.lineStyle(4, 0xFF0000);
                    graphics.moveTo(ax, ay);
                    graphics.lineTo(ax, by); 
          
                    if (by > ay)
                    { graphics.moveTo(ax,(ay+by)*0.5);  graphics.lineTo(ax+((b.cx<a.cx)?8:-8),(ay+by)*0.5);  }

                    if (by > ay) { dir = (b.cx<a.cx)?  2 : 1;  }

                  graphics.lineStyle(2,0);
              
                      graphics.moveTo(a.cx+a.cw*0.5,a.cy+a.ch*0.5);
                      graphics.lineTo(b.cx+b.cw*0.5, b.cy+b.ch*0.5);
              
                  if (dir == 1 && (prev & 2 )>0) { continue; }
                  if (dir == 2 && (prev & 1 )>0) { continue; }
                  if (dir == 4 && (prev & 8 )>0) { continue; }
                  if (dir == 8 && (prev & 4 )>0) { continue; }
              
                  b.prev = a.prev | dir;
                
                  b.test = curTest;
                
                vr[it] = b;
                it += 1; if (it>=512) { it = 511; } 
              }//nextk   
              
         }//wend           
            
        }//floodrect


        
        
        
        
    }//classend
}

internal class xRect
{
   public var cx:Number = 0;
   public var cy:Number = 0;
   public var cw:Number = 0;
   public var ch:Number = 0;    
    
   public var test:int = -1; 
   
   public var prev:int = 0;
    
   public var vecNext:Vector.<xRect> = new Vector.<xRect>(0,false);  
    
}//xrect