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

Stretch Camera

ステージクリックで変形!
Get Adobe Flash player
by abtky 10 Oct 2010
    Embed
/**
 * Copyright abtky ( http://wonderfl.net/user/abtky )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nTGB
 */

package {
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.filters.*;
    import flash.media.*;
    import caurina.transitions.Tweener;
    
    public class Main extends Sprite {
        
        private const _WIDTH:int = 465;
        private const _HEIGHT:int = 465;
        private const _VALUE:Number = -.3;
        
        private var _video:Video;
        private var _camera:Camera;
        private var _map:BitmapData;
        private var _filter:DisplacementMapFilter;
        private var _value:Number;
        private var _flg:Boolean;
        
        public function Main(){
            _camera = Camera.getCamera();
            
            _map = new MapBitmap( _WIDTH , _HEIGHT );
            
            _video = new Video( _map.width , _map.height );
            _video.attachCamera( _camera );
            _video.scaleX = -1;
            _video.x = _video.width;
            
            _value = _VALUE;
            
            var blur:BlurFilter = new BlurFilter( 4 , 4 , 4 );
            _map.applyFilter( _map , new Rectangle( 0, 0, _map.width , _map.height ) , new Point() , blur );
            _filter = new DisplacementMapFilter();
            _filter.componentY = BitmapDataChannel.RED;
            _filter.componentX = BitmapDataChannel.BLUE;
            _filter.mapBitmap = _map;
            _video.filters = [ _filter ];
            addChild( _video );
            buttonMode = true;
            stage.addEventListener( MouseEvent.CLICK , _click );
        }
        private function _click( event:MouseEvent ):void {
            
            _flg = ! _flg;
            _value = int( _flg ) * _VALUE;
            var tween:Object = {
                scaleX : _map.width * _value ,
                scaleY : _map.height * _value ,
                onUpdate : function():void{ _video.filters = [ _filter ] } ,
                time : 1
            }
            var filterScaleX:Number = _map.width * _value;
            var filterScaleY:Number = _map.height * _value;
            Tweener.addTween( _filter , tween );
        }
    }
}

import flash.display.*;
import flash.geom.*;
class MapBitmap extends BitmapData {
    public function MapBitmap( width:int , height:int ){
        super( width , height );
        var matrix:Matrix = new Matrix();
        var radius:Number = Math.PI * 2;
        matrix.createGradientBox( width , height , radius , radius );
        
        var blue:Shape = new Shape();
        var blueG:Graphics = blue.graphics;
        var bColors:Array = [ 0x000080 , 0x0 , 0x0000FF , 0x000080 ];
        var alphas:Array = [ 1 , 1 , 1 , 1 ];
        var ratios:Array = [ 0x0 , 0x33 , 0xCC , 0xFF ];
        blueG.beginGradientFill( GradientType.LINEAR , bColors , alphas , ratios , matrix );
        blueG.drawRect( 0, 0, width , height );
        blueG.endFill();
        
        var red:Shape = new Shape();
        var redG:Graphics = red.graphics;
        var rColors:Array = [ 0x800000 , 0x0 , 0xFF0000 , 0x800000 ];
        matrix.rotate( Math.PI / 2 );
        redG.beginGradientFill( GradientType.LINEAR , rColors , alphas , ratios , matrix );
        redG.drawRect( 0, 0, width , height );
        redG.endFill();
        red.blendMode = BlendMode.ADD;
        
        var sp:Sprite = new Sprite();
        sp.addChild( blue );
        sp.addChild( red );
        
        draw( sp );
    }
}