flash on 2012-9-18

by mutantleg
♥0 | Line 95 | Modified 2012-09-18 18:01:43 | MIT License
play

ActionScript3 source code

/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hlBS
 */

package {
    import flash.display.Graphics;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        
        public var vecMap:Vector.<int>;
        public var vecProc:Vector.<int>;        
        public var mwidth:int = 0;
        public var mheight:int = 0;
        
        public function FlashTest() {
            // write as3 code here..
            
            var num:int = 0;
            mwidth = 16;
            mheight = 16;
            num = mwidth * mheight;
            
            vecMap = new Vector.<int>(num, false);
            vecProc = new Vector.<int>(num, false);
            
            for (i =0; i < num; i++)
            {
                vecMap[i] = Math.random() * 2;
                vecProc[i] = 0;
            }//nexti
              
            for (i =0; i < mwidth; i++)
            { vecMap[i] = 0;
              vecMap[i + (mheight-1)*mwidth] = 0;
            }  
            
            for (i = 0; i<mheight; i++)
            {
             vecMap[i*mwidth] = 0;
             vecMap[i*mwidth + (mwidth-1)] = 0;   
            }
              
            var g:Graphics;
            g = graphics;
            g.clear();
            //g.lineStyle(2,0);
            var i:int;
            var k:int;
            var t:int;
            
            for (i = 1; i < (mheight-1); i++)
            {
                for (k = 1; k < (mwidth-1);k++)
                {
                    t = k + (i*mwidth);
                    if (vecMap[t-mwidth] > 0)
                    { vecProc[t] += 1; }
                    if (vecMap[t+mwidth] > 0)
                    { vecProc[t] += 2;}
                    if (vecMap[t-1] > 0)
                    { vecProc[t] += 4;}
                    if (vecMap[t+1] > 0)
                    { vecProc[t] += 8; }
                    
                }//nextk
            }//nexti
            
            var f:int;
            var bUp:Boolean = false;
            var bDown:Boolean = false;
            var bLeft:Boolean = false;
            var bRight:Boolean = false;
            
            for (i = 0; i < mheight; i++)
            {
                for (k = 0; k < mwidth; k++)
                {
                 t = vecMap[ k+ (i*mwidth)];
                 f = vecProc[ k + (i*mwidth)];
                    if (t == 0) { continue;}
                    g.lineStyle(0,0xFF0000);
                    
                    g.beginFill(0xFF0000,1);
                    g.drawRect(k*16,i*16,16,16);
                    g.endFill();
                    
                    bUp = (f & 1) > 0;
                    bDown = (f & 2) > 0;
                    bLeft = (f & 4) > 0;
                    bRight = (f & 8) > 0;
                    
                    g.lineStyle(4,0);
                    if (!bUp)
                    { g.moveTo(k*16,i*16);
                      g.lineTo(k*16+16,i*16);
                    }  
                    if (!bDown)
                    {
                      g.moveTo(k*16,i*16+16);
                      g.lineTo(k*16+16,i*16+16);  
                    }
                    
                    if (!bLeft)
                    {
                      g.moveTo(k*16,i*16);
                      g.lineTo(k*16,i*16+16);   
                    }
                    
                    if (!bRight)
                    {
                     g.moveTo(k*16+16, i*16);
                     g.lineTo(k*16+16, i*16+16);  
                     }
                           
                }//nextk
            }//nexti
           
           
            
        }//ctor
        
    }//classend
}