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: camera of undefined

@autoher : muraken (undefined Inc.)
// forked from muraken's camera of undefined
// @autoher : muraken (undefined Inc.)

package {
import caurina.transitions.Tweener;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.Camera;
import flash.media.Video;

[SWF(width="465", height="465", backgroundColor="#141414", frameRate="40")]
public class NoiseDisplay extends Sprite {
    private var bmp:Bitmap;
    private const BMD_WIDTH:int = 240;
    private const BMD_HEIGHT:int = 240;
    private var baseColor:uint = 0xDFDFDF;
    private var baseBmd:BitmapData;
    private var editBmd:BitmapData;
    private var noiseBmd:BitmapData;
    private var sandstormBmd:BitmapData;
    private var sorce:DisplayObject;
    private var baseMatrix:Matrix;
    private var pointArray:Array;
    private var randArray1:Array;
    private var randArray2:Array;
    private var randNum1:Number;
    private var bmdUpNum:Number;
    private var video:Video;
    private var _bmp:Bitmap;
    private var camera_width:int;
    private var camera_height:int;
    
    private var screen:Sprite = new Sprite();
    private var tiles:Vector.<Tile> = new Vector.<Tile>();
    
    public function NoiseDisplay():void {
        camera_width = stage.stageWidth;
        camera_height = stage.stageHeight;
        video = new Video(camera_width, camera_height);
        var camera:Camera = Camera.getCamera();
        if (camera == null) {
            //error
            return;
        }
        video.attachCamera(camera);
        sorce = video;
        bmp = new Bitmap();
        //addChild(bmp);
        
        baseBmd = new BitmapData(BMD_WIDTH, BMD_HEIGHT, false, baseColor);
        editBmd = baseBmd.clone();
        noiseBmd = baseBmd.clone();
        sandstormBmd = baseBmd.clone();
        baseMatrix = new Matrix();
        pointArray = new Array(new Point(0, 0), new Point(0, 0), new Point(0, 0));
        randArray1 = new Array(Math.random() + 1, Math.random() + 1, Math.random() + 1);
        randArray2 = new Array(0, 0, 0);
        randNum1 =0.5;
        bmdUpNum = 0;
        bmp.bitmapData = noiseBmd;
        bmp.smoothing = true;
        bmp.visible = false;
        stage.addEventListener(Event.RESIZE, _onResize);
        addEventListener(Event.ENTER_FRAME, upDate);
        bmp.visible = true;
        sorce.visible = false;
        
        var r:Rectangle = noiseBmd.rect;
        var segH:uint = 8;
        var segV:uint = 12;
        var w:uint = r.width / segH >> 0;
        var h:uint = r.height / segV >> 0;
        
        var tb:BitmapData = new BitmapData(w, h, false, 0);
        var c:uint = 0;
        
        for (var i:uint = 0; i < segH; i++) 
        {
            for (var j:uint = 0; j < segV; j++) 
            {
                screen.addChild(tiles[c++] = new Tile(tb.clone(), new Rectangle(i * w, j * h, w, h), i, j));
            }
        }
        
        addChild(screen);
        
        _onResize(null);
    }
    private function _onResize(e:Event):void {
        var W:Number = stage.stageWidth;
        var H:Number = stage.stageHeight;
        baseMatrix = new Matrix();
        baseMatrix.scale(BMD_WIDTH/W, BMD_HEIGHT/H);
        screen.scaleX = W/BMD_WIDTH;
        screen.scaleY = H/BMD_HEIGHT;
        screen.x = bmp.y = 0;
    }
    private var _keyCnt:Number = 0;
    private function upDate(e:Event):void {
        var copy_bmd:BitmapData = baseBmd.clone();
        copy_bmd.draw(sorce, baseMatrix);
        editBmd = copy_bmd.clone();
        
        for (var i:int = 0; i < 3; i++) {
            if (randArray1[i] >= 1){
                --randArray1[i];
                randArray2[i] = Math.random() / 4 + 0.03;
            } 
            randArray1[i] = randArray1[i] + randArray2[i];
            _keyCnt += (48-_keyCnt) / 4;
            pointArray[i].x = Math.ceil(Math.sin(randArray1[i] * Math.PI * 2) * randArray2[i] * _keyCnt*2);
            pointArray[i].y = 0;
        }
        
        var keyNum:Number = 1*(Math.abs(pointArray[0].x) + Math.abs(pointArray[1].x) + Math.abs(pointArray[2].x) + 8) / 4;

        i = BMD_HEIGHT;
        while (i--){
            var offset:Number = Math.sin(i / BMD_HEIGHT * (Math.random() / 8 + 1) * randNum1 * Math.PI * 2)* 0.8 * keyNum * keyNum;
            editBmd.copyPixels(copy_bmd, new Rectangle(offset, i, BMD_WIDTH - offset, 1), new Point(0, i));
        }
        sandstormBmd.noise(int(Math.random() * 1000), 0, 255, 7, false);
        var sandNum:Number = 40;
        editBmd.merge(sandstormBmd, editBmd.rect, new Point(0,0), sandNum, sandNum, sandNum, 0);
        noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[0], BitmapDataChannel.RED, BitmapDataChannel.RED);
        noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[1], BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
        noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[2], BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);
        
        var n:uint = tiles.length;
        for (var k:uint = 0; k < n; k++) 
        {
            var tile:Tile = tiles[k];
            tile.update(noiseBmd);
            tile.rotationY -= tile.rotationY * 0.125;
        }
    }
}
}

import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;

class Tile extends Sprite
{
    private var _rect:Rectangle;
    private var _bitmap:Bitmap;
    private var _px:Number = 0;
    private var _py:Number = 0;
    
    public function Tile(bitmapData:BitmapData, rect:Rectangle, i:int, j:int)
    {
        addChild(_bitmap = new Bitmap(bitmapData));
        _rect = rect;
        this.x = rect.x + rect.width * .5 + 1 * i;
        this.y = rect.y + rect.height * .5 + 1 * j;
        _bitmap.x = -rect.width * .5;
        _bitmap.y = -rect.height * .5;
        
        addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    }
    
    public function update(bitmapData:BitmapData):void
    {
        _bitmap.bitmapData.copyPixels(bitmapData, _rect, PT);
    }
    
    private function mouseMoveHandler(event:MouseEvent):void 
    {
        var nx:Number = event.localX;
        this.rotationY += (nx - _px) * 20;
        _px = nx;
    }
    
    
}

const PT:Point = new Point();