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: InfiniteQuest

Theme:
* Play with BitmapPatterBuilder.
* Purpose of this trial is to find the possibility of the dot pattern.
*
* by Takayuki Fukatsu aka fladdict
Get Adobe Flash player
by acoldnovember 22 Jul 2009
/**
 * Copyright acoldnovember ( http://wonderfl.net/user/acoldnovember )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/k1ed
 */

// forked from osamX's InfiniteQuest
/**
 * Theme:
 * Play with BitmapPatterBuilder.
 * Purpose of this trial is to find the possibility of the dot pattern.
 *
 * by Takayuki Fukatsu aka fladdict
 **/
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.geom.Rectangle;

    
    
    public class Professional extends Sprite {
		private const WIDTH:uint = 11;
		private const HEIGHT:uint = 6;
		private const SCALE:uint = 3;
		private var mapSprite:Sprite;
		private var mapArray:Array;
		private var dotArray:Array;
		
        public function Professional() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
			mapSprite = new Sprite();
			mapSprite.scaleX = SCALE;
			mapSprite.scaleY = SCALE;
			mapSprite.x = -SCALE * 16;
			mapSprite.y = -16;
			
			
			initDot();
			initMap();
			drawMap();
			
			this.addChild( mapSprite );

			
        }		
		
		private function drawMap():void {
			for (var j:uint = 0; j < HEIGHT; j++ ) {
				for ( var i:uint = 0; i < WIDTH; i++ ) {
					for (var yy:uint = 0; yy < 16; yy++) {
						for (var xx:uint = 0; xx < 16; xx++) {
							dotArray[16 * j + yy][16 * i + xx] = patterns[mapArray[j][i]][yy][xx];
						}
					}
				}
			}
			var g:Graphics = mapSprite.graphics;
			g.beginBitmapFill(BitmapPatternBuilder.build(dotArray,[0xFF92DC00, 0xFF319600, 0xFFFFB848, 0xFFB97A00, 0xFF000000,0xFFFFAA00, 0xFFFE0000, 0xFFFFAA25, 0xFF6BC6FF, 0xFFB1E2FF, 0xFF0092DC] ) );
			g.drawRect(0,5,WIDTH*16,int(465/SCALE)+1);
            g.endFill();
		}
		
		
		private function initMap():void {
			mapArray = new Array();
			for (var j:uint = 0; j < HEIGHT; j++) {
				mapArray[j] = new Array();
				for (var i:uint = 0; i < WIDTH; i++) {
					if (j == HEIGHT - 1) mapArray[j][i] = 0;
					else mapArray[j][i] = maprand();
				}
			}
		}
		
		private function initDot():void {
			dotArray = new Array();
			for (var j:uint = 0; j < HEIGHT*16; j++) {
				dotArray[j] = new Array();
				for (var i:uint = 0; i < WIDTH*16; i++) {
					dotArray[j][i] = 0;
				}
			}
		}
		
		private function maprand():uint {
			var rand:uint = int(Math.random() * 100);
			if (rand == 0) return 4;
			else if (rand < 5) return 5;
			else if (rand < 20) return 2;
			else if (rand < 30) return 3;
			else if (rand < 50) return 1;
			return 0;
		}
		
		
		
        private const patterns:Array =
				[
				//Lawn
                [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
				 [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 0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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2],
				 [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]]
				,
				//Tree1
                [[0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0],
				 [0, 0, 4, 1, 1, 4, 0, 0, 0, 0, 4, 1, 1, 4, 0, 0],
				 [0, 4, 1, 1, 1, 1, 4, 0, 0, 4, 1, 1, 1, 1, 4, 0],
				 [4, 1, 1, 1, 4, 4, 1, 1, 4, 1, 1, 1, 4, 4, 1, 1],
				 [4, 4, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1],
				 [4, 1, 4, 4, 1, 1, 1, 4, 4, 1, 4, 4, 1, 1, 1, 4],
				 [4, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1],
				 [4, 4, 1, 1, 1, 1, 4, 1, 4, 4, 1, 1, 1, 1, 4, 1],
				 [4, 1, 1, 1, 4, 4, 1, 4, 4, 1, 1, 1, 4, 4, 1, 4],
				 [4, 4, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1],
				 [4, 4, 4, 1, 1, 1, 1, 1, 4, 4, 4, 1, 1, 1, 1, 1],
				 [0, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 4, 4, 0],
				 [0, 0, 4, 4, 5, 4, 0, 0, 0, 0, 4, 4, 5, 4, 0, 0],
				 [0, 4, 4, 5, 5, 4, 4, 0, 0, 4, 4, 5, 5, 4, 4, 0],
				 [4, 4, 5, 5, 4, 5, 4, 4, 4, 4, 5, 5, 4, 5, 4, 4],
				 [0, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 4, 4, 0]]
				,
				//Tree2
                [[0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0],
				 [0, 0, 0, 0, 4, 1, 1, 1, 1, 1, 1, 4, 4, 0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7, 6, 6, 7, 4],
				 [4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4],
				 [4, 7, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 4],
				 [4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4],
				 [4, 7, 6, 6, 7, 6, 7, 4, 4, 7, 6, 7, 6, 6, 7, 4],
				 [4, 7, 6, 6, 7, 6, 7, 7, 7, 7, 6, 7, 6, 6, 7, 4],
				 [4, 7, 6, 6, 7, 6, 6, 6, 6, 6, 6, 7, 6, 6, 7, 4],
				 [4, 7, 6, 6, 7, 6, 6, 6, 6, 6, 6, 7, 6, 6, 7, 4],
				 [4, 7, 6, 6, 7, 6, 6, 6, 6, 6, 6, 7, 6, 6, 7, 4],
				 [4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4],
				 [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]]
				,
				//Water
                [[ 8,10,10, 9, 9,10, 8, 8, 8,10,10, 9, 9,10, 8, 8],
				 [10,10, 9, 8, 8, 9,10,10,10,10, 9, 8, 8, 9, 8, 8],
				 [ 9, 9,10, 8,10,10,10, 8, 9, 9,10, 8,10,10,10, 8],
				 [ 8, 8, 9,10,10,10, 8, 9, 8, 8, 9,10,10,10, 8, 9],
				 [ 8, 8,10,10, 9, 9,10, 8, 8, 8,10,10, 9, 9,10, 8],
				 [10,10,10, 9, 8, 8, 9,10,10,10,10, 9, 8, 8, 9,10],
				 [ 8, 9, 9,10, 8,10,10,10, 8, 9, 9,10, 8,10,10,10],
				 [ 9, 8, 8, 9,10,10,10, 8, 9, 8, 8, 9,10,10,10, 8],
				 [ 9,10, 8, 8, 8,10,10, 9, 9,10, 8, 8, 8,10,10, 9],
				 [ 8, 9,10,10,10,10, 9, 8, 8, 9,10,10,10,10, 9, 8],
				 [10,10,10, 8, 9, 9,10, 8,10,10,10, 8, 9, 9,10, 8],
				 [10,10, 8, 9, 8, 8, 9,10,10,10, 8, 9, 8, 8, 9,10],
				 [ 9, 9,10, 8, 8, 8,10,10, 9, 9,10, 8, 8, 8,10,10],
				 [ 8, 8, 9,10,10,10,10, 9, 8, 8, 9,10,10,10,10, 8],
				 [ 8,10,10,10, 8, 9, 9,10, 8,10,10,10, 8, 9, 9,10],
				 [10,10,10, 8, 9, 8, 8, 9,10,10,10, 8, 9, 8, 8, 9]]
				 ];
				 

    }
}


/**-----------------------------------------------------
 * Use following BitmapPatternBuilder class 
 * 
 * DO NOT CHANGE any codes below this comment.
 *
 * -----------------------------------------------------
*/
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
    
class BitmapPatternBuilder{
    /**
     * creates BitmapData filled with dot pattern.
     * First parameter is 2d array that contains color index for each pixels;
     * Second parameter contains color reference table.
     *
     * @parameter pattern:Array 2d array that contains color index for each pixel.
     * @parameter colors:Array 1d array that contains color table.
     * @returns BitmapData
     */
    public static function build(pattern:Array, colors:Array):BitmapData{
        var bitmapW:int = pattern[0].length;
        var bitmapH:int = pattern.length;
        var bmd:BitmapData = new BitmapData(bitmapW,bitmapH,true,0x000000);
        for(var yy:int=0; yy<bitmapH; yy++){
            for(var xx:int=0; xx<bitmapW; xx++){
                var color:int = colors[pattern[yy][xx]];
                bmd.setPixel32(xx, yy, color);
            }
        }
        return bmd;
    }
    
    /**
     * short cut function for Graphics.beginBitmapFill with pattern.
     */
    public static function beginBitmapFill(pattern:Array, colors:Array, graphics:Graphics):void{
        var bmd:BitmapData = build(pattern, colors);
        graphics.beginBitmapFill(bmd);
        bmd.dispose();        
    }
}