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: fladdict challenge for professionals

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

/**
 * 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.events.Event;
    
    [SWF(width="465", height="465", backgroundColor="0x00", frameRate="90")]
    public class checkMate extends Sprite {
    	private var counter:int = 0;
    	private var pattern:BitmapData;
    	
    	private var base:Sprite = new Sprite();
    	private var basebase:Sprite = new Sprite();
    	
        public function checkMate() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            addChild(base);
           
            pattern = sampleVeader();
            
            var g:Graphics = base.graphics;
            g.beginBitmapFill(pattern);
            g.drawRect(0,0,480,480);
            g.endFill();
            //trace(pattern.width);
            
        }
        
        private function scaleBase():void
        {
        	basebase.rotation = Math.abs(stage.stageWidth/2 - mouseX);
        }
        
        private var arrA:Array = 
        		[[0,0,0,0,0,0,0,0,0],
				 [0,0,0,0,0,0,0,0,0],
                 [0,0,1,0,0,0,1,0,0],
                 [0,0,1,0,1,0,1,0,0],
                 [0,0,0,0,0,0,0,0,0],
                 [0,0,0,1,1,1,0,0,0],
                 [0,0,0,1,0,1,0,0,0],
                 [0,0,0,0,0,0,0,0,0],
 			 	 [0,0,0,0,0,0,0,0,0]];
        private var arrB:Array = 
        		[[0,0,0,0,0,0,0,0,0],
				 [0,0,0,0,0,0,0,0,0],
                 [0,0,1,1,0,1,1,0,0],
                 [0,0,0,1,1,1,0,0,0],
                 [0,0,0,1,1,1,0,0,0],
                 [0,0,1,1,1,1,1,0,0],
                 [0,0,0,1,1,1,0,0,0],
                 [0,0,0,0,0,0,0,0,0],
 				 [0,0,0,0,0,0,0,0,0]];
         private var arrC:Array = 
        		[[0,0,0,0,0,0,0,0,0],
				 [0,0,0,0,0,0,0,0,0],
                 [0,0,0,1,1,1,0,0,0],
                 [0,0,1,0,1,0,1,0,0],
                 [0,0,1,1,1,1,1,0,0],
                 [0,0,1,1,1,1,1,0,0],
                 [0,0,1,0,1,0,1,0,0],
                 [0,0,0,0,0,0,0,0,0],
 				 [0,0,0,0,0,0,0,0,0]];
         private var arrD:Array = 
        		[[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,1,0,1,0,1,0,0],
                 [0,0,0,0,1,0,0,0,0],
                 [0,0,0,0,1,0,0,0,0],
                 [0,0,1,0,1,0,1,0,0],
                 [0,0,0,0,0,0,0,0,0],
				 [0,0,0,0,0,0,0,0,0]];
        private var arrE:Array = 
       		   [[0,0,0,0,0,0,0,0,0],
				[0,0,0,0,0,0,0,0,0],
                [0,0,1,1,1,1,1,0,0],
                [0,0,0,0,1,0,0,0,0],
                [0,0,0,1,1,1,0,0,0],
                [0,0,1,1,1,1,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]];
        private var arrF:Array = 
       		   [[0,0,0,0,0,0,0,0,0],
				[0,0,0,0,0,0,0,0,0],
                [0,0,0,1,1,1,0,0,0],
                [0,0,1,0,0,0,1,0,0],
                [0,0,0,1,0,1,0,0,0],
                [0,0,0,1,0,1,0,0,0],
                [0,0,0,1,1,1,0,0,0],
                [0,0,0,0,0,0,0,0,0],
 				[0,0,0,0,0,0,0,0,0]];
                 
        public function sampleVeader():BitmapData{
        	
        	var arrX:Array = randomInvaderSide();
        	var arrX2:Array = randomInvaderSide();
        	var i:int,t:int;
        	var alen:int = arrX.length;
        	
        	for(t=0; t<30; t++) {
        		arrX2 = randomInvaderSide();
	        	for(i=0; i<alen; i++) {
	        		arrX.push(arrX2[i]);
	        	}
        	}
        	return BitmapPatternBuilder.build(
                arrX,
                [0xffffffff, 0xcc000000]
                );
        }          
       
        
        
        private function randomInvaderSide(ramnum:Number=0.4):Array {
        	var arrX:Array = new Array();
        	var tempA:Array = arrA; var tempB:Array = arrB;
        	var ram:Number = Math.random();
			if(ram>=0&&ramnum<0.3){ tempA = arrB; tempB = arrC;}
			if( ram>=0.3&&ramnum<0.6) { tempA = arrC; tempB = arrE;} 			
			if( ram>=0.6&&ramnum<1.0) { tempA = arrD; tempB = arrA;}
    			
        	arrX = adArrToArr(tempA,tempB);
        	
        	var swarr:Array = arrA;
        	
        	for(var i:int=0; i<60; i++) {
    			ram = Math.random();
    			if(ram>=0&&ramnum<0.2) swarr = arrA;
    			if( ram>=0.2&&ramnum<0.4) swarr = arrB;    			
    			if( ram>=0.4&&ramnum<0.6) swarr = arrC;
    			if( ram>=0.6&&ramnum<0.8) swarr = arrD;
    			if( ram>=0.8&&ramnum<0.9) swarr = arrE;
    			if( ram>=0.9&&ramnum<1.0) swarr = arrF;
        		arrX = adArrToArr(arrX,swarr);
	       	}
        	return arrX;
        }
       
        
        public function adArrToArr(arA:Array, arB:Array):Array
        {
        	var alen:int = arA[0].length;
        	var blen:int = arB[0].length;
        	var totalLen:int = alen+blen;
        	var arr:Array = new Array(arA.length);
        	var i:int,t:int;
        	for(i=0; i<arA.length; i++) {
        		arr[i] = new Array();
        		for(t=0; t<alen; t++) {
        			arr[i].push(arA[i][t]);
        		}
        	}
        	
        	for(i=0; i<arB.length; i++) {
        		for(t=0; t<blen; t++) {
        			arr[i].push( arB[i][t] );
        		}
        	}
        	
        	return arr;
        }
        
        
    }
}

/**-----------------------------------------------------
 * 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();        
    }
}