Random Tile

by tkinjo
♥2 | Line 23 | Modified 2011-03-24 15:28:24 | MIT License
play

ActionScript3 source code

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

package  
{
    import flash.display.Sprite;
    
    [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="60")]
    /**
     * ...
     * @author tkinjo
     */
    public class Main extends Sprite
    {
        private const NUM_TILE:uint = 10;
        private const BORDER_SIZE:uint = 1;
        
        public function Main() 
        {
            var tileSize:uint = ( stage.stageWidth / NUM_TILE ) - BORDER_SIZE;
            trace( tileSize );
            
            //graphics.beginFill( 0 );
            
            for ( var i:uint = 0; i < NUM_TILE; i++ )
                for ( var j:uint = 0; j < NUM_TILE; j++ )
                    drawRandomTile( i * ( tileSize + BORDER_SIZE ), j * ( tileSize + BORDER_SIZE ), tileSize, tileSize );
            
            graphics.endFill();
        }
        
        private function drawRandomTile( x:Number, y:Number, width:Number, height:Number ):void {
            
            graphics.beginFill( Math.random() * 0xffffff );
            
            graphics.drawRect( x, y, width, height );
            
            //graphics.endFill();
        }
    }

}