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

code on 2008-12-18

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.StatusEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.ColorTransform;
    import flash.geom.Rectangle;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.display.BlendMode;
    public class Effect03 extends Sprite {
        private var twinkle:BitmapData;
        private var twinkleImageList:Array = [];
        private var twinkleList:Array = [];
    
        private var shaderData:Class;
        private var my_cam:Camera;
        private var video:Video;
        private var bdCamera:BitmapData;
        private var bdCameraOld:BitmapData;
        private var bdCamera1:BitmapData;
        private var bdCamera2:BitmapData;
        private var bdCamera3:BitmapData;
        private var mtReverse:Matrix;
        private var mt:Matrix;
        private var pt:Point;
        private var ct:ColorTransform
        private var ct2:ColorTransform
        private var bdColorChange:BitmapData;
        private var bdWhite:BitmapData;
        private var bdBlack:BitmapData;
        private var bdList:Array;
        private var count:int = 0;
        public var activeList:Array = [];
        public var cameraEnabled:Boolean = false;
    
        private var bFull:Boolean = true;
        public function Effect03() {
            addEventListener(Event.ADDED_TO_STAGE, added);
        }
        private function added(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, added);
            init();
        }
        private function init():void {
            my_cam = Camera.getCamera();
            my_cam.setMode(320, 240, 30, false);
            //my_cam.setMotionLevel(100, 10000);
            //my_cam.setQuality(100,5);
            my_cam.addEventListener(StatusEvent.STATUS,st);
            function st(e:StatusEvent):void {
                if (e.code == "Camera.Unmuted") {
                    my_cam.removeEventListener(StatusEvent.STATUS,st);
                    cameraEnabled = true;
                }
            }
            video = new Video();
            video.attachCamera(my_cam);

            bdCamera = new BitmapData(320, 240, false, 0x000000);
            bdCameraOld = new BitmapData(320, 240, false, 0x000000);
            bdCamera1 = new BitmapData(320, 240, false, 0x000000);
            bdCamera2 = new BitmapData(320, 240, false, 0x000000);
            bdCamera3 = new BitmapData(320, 240, false, 0x000000);
            
            var bm1:Bitmap = new Bitmap(bdCamera);
            addChild(bm1);
            bm1.x = 320;
            var bm2:Bitmap = new Bitmap(bdCamera2);
            addChild(bm2);
            bm2.y = 240;
            var bm3:Bitmap = new Bitmap(bdCamera3);
            addChild(bm3);
            bm3.x = 320;
            bm3.y = 240;
            
            mtReverse = new Matrix(-1, 0, 0, 1, 320, 0);
            mt = new Matrix();
            pt = new Point();
            ct = new ColorTransform();
            
            bdBlack = new BitmapData(320, 240, false, 0x000000);
            
            addChild(video);
            video.scaleX = -2;
            video.scaleY = 2;
            video.x = 640;
            stage.addEventListener(MouseEvent.MOUSE_DOWN, changeScreen);
            addEventListener(Event.ENTER_FRAME, loop);
            
                           twinkle = new BitmapData(4,4,true,0xFFFFFFFF);
    
            
        }
        private function changeScreen(e:MouseEvent):void {
            bFull = !bFull;
            if (bFull) {
                video.scaleX = -2;
                video.scaleY = 2;
                video.x = 640;
            } else {
                video.scaleX = -1;
                video.scaleY = 1;
                video.x = 320;
            }
        }
        
        private function loop(e:Event):void {
            //trace(my_cam.currentFPS);
            /*if (count++ == 1) {
                count = 0;
            }*/
            
            bdCamera.draw(video, mtReverse);
            bdCamera.draw(bdCameraOld, mt, ct, "difference");
            
            bdCamera2.draw(bdCamera);
            bdCamera2.applyFilter(bdCamera2, bdCamera2.rect, pt, new BlurFilter(4, 4, 3));
            bdCamera2.threshold(bdCamera2, bdCamera2.rect, pt, ">", 0xff222222, 0xffFFFFFF);
            bdCamera2.threshold(bdCamera2, bdCamera2.rect, pt, "<", 0xff555555, 0xff000000);
            
            var rect:Rectangle = bdCamera2.getColorBoundsRect(0xFFFFFF, 0xFFFFFF, true);
            var num:int = 0;
            if (!rect.isEmpty()) {
                bdCamera3.draw(video, mtReverse);
                for (var yy:int = rect.y; yy < 240; yy++) {
                    for (var xx:int = rect.x; xx < 320; xx++) {
                        if (bdCamera2.getPixel(xx, yy) == 0xFFFFFF) {
                            num++;
                            bdCamera2.floodFill(xx, yy, num);
                        }
                    }
                }            
                var bd:BitmapData = new BitmapData(1, 1, true, 0x33FF0000);
                for (var i:int = 1; i <= num; i++) {
                    var rect2:Rectangle = bdCamera2.getColorBoundsRect(i, i, true);
                    if (!rect2.isEmpty() && rect2.width < 100) {
                        var mt2:Matrix = new Matrix(rect2.width, 0, 0, rect2.height, rect2.x, rect2.y);
                        bdCamera3.draw(bd, mt2);
                        //
                        var nn:Number = Math.floor(rect.width * rect.height / 50000) + 1;
                        for (var n:int = 0; n < nn; n++) {
                            addTwinkle(rect2);
                        }
                    }
                }
                bdCameraOld.draw(video, mtReverse);
            }
            
            for (i = twinkleList.length - 1; i >= 0; i--) {
                var tw:Twinkle = Twinkle(twinkleList[i]);
                tw.update();
                if (bFull) {
                    tw.x *= 2;
                    tw.y *= 2;
                }
                if (tw.del) {
                    tw.remove();
                    removeChild(tw);
                    twinkleList.splice(i, 1);
                }
            }
        }
        private function addTwinkle(rect:Rectangle):void {
            var rnd:int = Math.floor(Math.random()*twinkleImageList.length);
            var bm:Bitmap = new Bitmap(twinkle);
            var tw:Twinkle = new Twinkle();
            tw.bm = bm;
            tw.addChild(bm);
            addChild(tw);
            twinkleList.push(tw);
            tw.blendMode = BlendMode.ADD;
            //tw.scaleX = tw.scaleY = (rect.width * rect.height) / 10000;
            tw.scaleX = tw.scaleY = Math.random()*0.4 + 0.1;
            tw.x = Math.random() * rect.width + rect.x;
            tw.y = Math.random() * rect.height + rect.y;
            tw.xx = tw.x;
            tw.yy = tw.y;
            bm.x = - bm.width / 2;
            bm.y = - bm.height / 2;
        }
    }
}
import flash.display.Bitmap;
import flash.display.Sprite;
class Twinkle extends Sprite {
    public var bm:Bitmap;
    public var del:Boolean = false;
    private var vy:Number;
    private var ay:Number;
    private var va:Number;
    public var xx:Number;
    public var yy:Number;
    function Twinkle() {
        va = Math.random() / 100 + 0.01;
        vy = 0;
        ay = -0.03;
    }
    public function update():void {
        rotation += 3;
        yy += vy;
        vy += ay;
        alpha -= va;
        x = xx;
        y = yy;
        if (alpha <= 0) {
            del = true;
        }
    }
    public function remove():void {
        removeChild(bm);
    }
}