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

(2進数を可視化)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
* 
* 
* 増えていく数字を2進数にして可視化するとこんな感じ?
/**
 * Copyright KinkumaDesign ( http://wonderfl.net/user/KinkumaDesign )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7PEk
 */

/**
 * Theme:
 * Play with BitmapPatterBuilder.
 * Purpose of this trial is to find the possibility of the dot pattern.
 *
 * by Takayuki Fukatsu aka fladdict
 * 
 * 
 * 増えていく数字を2進数にして可視化するとこんな感じ?
 **/
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;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
    
    [SWF(width="480", height="480", frameRate="24", backgroundColor="#000000")]
    public class Professional extends Sprite {
		public var cnt:int;
		public var baseInts:Array;
		public var colors:Array = [0xff00ff00, 0xff000000];
		public var myg:Graphics;
		public var canvasBmd:BitmapData;
		
        public function Professional() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
			canvasBmd = new BitmapData(32, 480);
            myg = this.graphics;
			cnt = 0;
			baseInts = [0];
			this.stage.addEventListener(Event.ENTER_FRAME, ef);
        }
		
		private function ef(e:Event):void 
		{
			if (baseInts.length > 160) {
				baseInts = [0];
				cnt = 0;
			}else {
				cnt++;
				baseInts.push(cnt);
			}

			var pt:BitmapData = BitmapPatternBuilder.build(getPattern(), colors);
			var mtx:Matrix = new Matrix();
			mtx.scale(3, 3);
			canvasBmd.lock();
			canvasBmd.fillRect(new Rectangle(0, 0, canvasBmd.width, canvasBmd.height), 0);
			canvasBmd.draw(pt, mtx);
			canvasBmd.unlock();
			
			myg.clear();
			myg.beginBitmapFill(canvasBmd);
			myg.drawRect(0, 0, 480, 480);
			myg.endFill();
		}
		
		private function getPattern():Array
		{
			//桁揃えしたものをパターンに変換
			var i:int;
			var len:int = baseInts.length;
			var digit:int = cnt.toString(2).length;
			var temp:int = (new int(1)) << digit;
			var current:int;
			var ar:Array;
			var pt:Array = new Array();
			for (i = 0; i < len; i++) {
				current = baseInts[i] | temp;//桁揃え
				ar = current.toString(2).substr(1).split("");
				pt.push(ar);
			}
			return pt;
		}
    }
}

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