3d bitmap render

by hemingway
wip
♥0 | Line 50 | Modified 2014-10-18 07:52:05 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    public class Main extends Sprite {
        public static const CANVAS_WIDTH:int = 465;
        public static const CANVAS_HEIGHT:int = 465;
        public static const CANVAS_DEPTH:int = 100;
        //render
        private var _canvas:Bitmap;
        private var _canvasData:BitmapData;
        private var _canvasCells:Vector.<Vector.<Vector.<uint>>>;
        private var _canvasShift:int;
        
        public function Main() {
            this._canvasShift = 8;
            this._canvasData = new BitmapData(CANVAS_WIDTH, CANVAS_HEIGHT, false);
            this._canvas = new Bitmap(this._canvasData);
            this._canvasCells = new Vector.<Vector.<Vector.<uint>>>(465, true);
        
            this.initializeDisplay();         
            
            this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
        }
        
        private function addedToStageHandler($event:Event):void {
            this.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
            
            this.addChild(this._canvas);
            
            
        }
        
        private function initializeDisplay():void {
            for (var $z:int = 0; $z < CANVAS_DEPTH; $z++) {
                this._canvasCells[$z] = new Vector.<Vector.<uint>>;
                
                for (var $y:int = 0; $y < CANVAS_HEIGHT; $y++) {
                    this._canvasCells[$z][$y] = new Vector.<uint>;
                    
                    for (var $x:int = 0; $x < CANVAS_WIDTH; $x++) {
                        if ($z < 51) {
                            this._canvasCells[$z][$y][$x] = 0;
                        }else if ($z == 51) {
                            this._canvasCells[$z][$y][$x] = 0xDCDCDC;
                        }else {
                            this._canvasCells[$z][$y][$x] = 0x00FF00;
                        }                    
                    }
                }
            } 
            
            for (var $mY:int = 50; $mY < 100; $mY++) {
                for (var $mX:int = 50; $mX < 100; $mX++) {
                    this._canvasData.setPixel32($mX, $mY, this._canvasCells[50][$mY][$mX]);
                }
            }
        }
    }
}