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

Camera Pixel View

Get Adobe Flash player
by Tomas1080 01 Oct 2011
package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.Camera;
    import flash.media.Video;
    import net.hires.debug.Stats;

    [SWF(width="465",height="465")]
    public class Main extends Sprite
    {
        
        private var _video:Video;
        private var _bitmapdata:BitmapData;
        
        public function Main() 
        {
            
            if (stage) init()
            else addEventListener(Event.ADDED_TO_STAGE, init);
            
            
        }
        
        private function init(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            var _camera:Camera = Camera.getCamera();
            _camera.setMode(stage.stageWidth, stage.stageHeight, 60);
            
            _video = new Video(stage.stageWidth, stage.stageHeight);
            _video.attachCamera(_camera);
            
            _bitmapdata = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFFFF);
            var _bitmap:Bitmap = new Bitmap(_bitmapdata);
            
            addChild(_bitmap);
            
            addEventListener(Event.ENTER_FRAME, loop);
        }
        
        private function loop(e:Event):void 
        {
            var bmpd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFFFFF);
            bmpd.draw(_video);
            var pix:Pixels = new Pixels(bmpd, bmpd.width, bmpd.height);
            
            var data:BitmapData = new BitmapData(pix.width, pix.height,true);
            
            data.lock();
            for (var i:int = 0; i < pix.array.length; i ++) {
                var c:ColorManager = pix.array[i] as ColorManager;
                if (c.color != 0xFFFFFF) {
                    var _blue:uint = c.color & 0xFF;
                    var _green:uint = c.color >> 8 & 0xFF;
                    var _red:uint = c.color >> 16;
                    
                    if (_red > 64 && _green > 64) {
                        data.setPixel(c.x, c.y, 0xFFFF00);
                    }else {
                        data.setPixel(c.x, c.y, 0);
                    }
                }
                
                
            }
            data.unlock();
            
            _bitmapdata.draw(data);
        }

    }

}


import flash.display.BitmapData;

class Pixels
{
    private var _bmpd:BitmapData;
    private var _array:Array = [];
    
    private var _height:Number;
    private var _width:Number;
    
    public function Pixels(bitmapdata:BitmapData, w:int,h:int )
    {
        _bmpd = bitmapdata;
        _height = h;
        _width = w;
        init();
    }
    
    private function init():void 
    {    
        for (var i:int = 0; i < height; i += 3) {
            for (var j:int = 0; j < width; j += 3 ) {
                if (_bmpd.getPixel(j, i) < 0xCCCCCC) {
                    var _c:ColorManager = new ColorManager();
                    _c.x = j;
                    _c.y = i;
                    _c.color = _bmpd.getPixel(j, i);
                    _array.push(_c);
                }
            }
        }
    }
    
    public function get array():Array 
    {
        return _array;
    }
    
    public function get height():Number 
    {
        return _height;
    }
    
    public function get width():Number 
    {
        return _width;
    }
}

class ColorManager
{
    public var x:Number;
    public var y:Number;
    public var color:uint;
    
    public function ColorManager()
    {
        
    }
}