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: WebCam HANABI

webカメラを繋いでご覧下さい。
webカメラで撮影された画像を花火にしてます。
Get Adobe Flash player
by escanar68 19 Nov 2009
/**
 * Copyright escanar68 ( http://wonderfl.net/user/escanar68 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/urAf
 */

// forked from 178ep3's WebCam HANABI
// forked from checkmate's Creek challenge
//webカメラを繋いでご覧下さい。
//webカメラで撮影された画像を花火にしてます。
package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.utils.*;
    import flash.system.*;
    import flash.media.Camera;
    import flash.media.Video;
    import com.flashdynamix.utils.*;

    [SWF(backgroundColor=0x000000, frameRate=60)]
    public class Sponsor extends Sprite {
     
        private var _particles:Vector.<Object>;
        private var _gradientMap:BitmapData; 
        private var _timer:Timer; 
   
        private const PARTICLES_LENGTH:int = 10000;

        private var _camera:Camera;
        private var _video:Video;
        private var _srcBmd:BitmapData;
        private var _srcCenter:Point = new Point(260,185);

        private function setup():void{
            _gradientMap= new BitmapData(200,10, true, 0);
            // addChild( new Bitmap( _gradientMap) ); // for debug
            updateGradientFill();
                
            shotFirework();
           
            _timer = new Timer( 5000, 0 );
            _timer.addEventListener( TimerEvent.TIMER, timerHadler );
            _timer.start();
            
            _loader = new Loader();
            _loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadComplete );
            _loader.load( new URLRequest("http://level0.kayac.com/space.jpg"), new LoaderContext(true) );
        }
        private var _loader:Loader;
        private function onLoadComplete(e:Event):void {
            addChildAt( _loader.content, 0 ); 
        }
        
        private function shotFirework():void {
            var len:uint = Math.random()*150+250;
            _particles = new Vector.<Object>();
            var radius:Number = Math.random()* 5 + 2;
            var radian:Number = Math.PI*2;
            for( var i :int=0; i<PARTICLES_LENGTH; i++ ) {
                var direction:Number = Math.random()*radian;
                var tx:Number = Math.sin(direction);
                var ty:Number = Math.cos(direction);
                
                var sl:Number = Math.random()* radius +2;
                var vl:Number = Math.random()* radius;
                
                const offsetX:int = 0, offsetY:int = - 45;
 
                var rad:Number = Math.random()*len;
                var angle:Number = i*Math.PI/180;
                var lx:Number = _srcCenter.x+Math.cos(angle)*rad;
                var ly:Number = _srcCenter.y+Math.sin(angle)*rad;
                var col:uint = _srcBmd.getPixel32(lx,ly);
                
                var particle :Object= {
                    lx:lx,
                    ly:ly,
                    col:col,
                    x: _center.x + tx*sl + offsetX,
                    y: _center.y + ty*sl + offsetY,
                    vx: tx*vl,
                    vy: ty*vl,
                    life: Math.random()* 30 + 170
                };
                _particles.push(particle);
            }
        }
        
        private const FRICTION:Number = 0.96;
        private const GRAVITY:Number = 0.006;
        private const WIND:Point = new Point(0.001,0 );
        
        private function updateCalcuration():void{
            for each( var p:Object in _particles ) {
                p.vx = (p.lx - p.x)*0.025 + Math.random()*0.01-.005;
                p.vy = (p.ly - p.y)*0.025 + GRAVITY + Math.random()*0.01-.005;
                p.x += p.vx;
                p.y += p.vy;
                p.life--;
            }
        }
        
        private function updateDrawing():void{
            _canvas.colorTransform( _canvas.rect, CTF );
            _canvas.lock();
            for each( var p:Object in _particles ) {
                if( p.life <= 0 ) continue;
                _canvas.setPixel32( p.x, p.y, p.col);
            }
            _canvas.unlock();
        }
         
        private function timerHadler (e:Event):void{
           updateGradientFill();
            _particles = null;
            shotFirework();
        }
        
        private const CTF:ColorTransform = new ColorTransform( 0.94, 0.94, 0.94, 0.9 );
        private const COLORS:Array = [ 0xFFCCFF, 0xFF9999, 0xFFFF99, 0x99CCFF, 0xCCFF99 ];
        private function updateGradientFill():void {
            var sp:Shape= new Shape();
            var color:uint = COLORS[ Math.random()*COLORS.length>>0];
            var mtx:Matrix = new Matrix();
            mtx.createGradientBox(200, 0, 0, 0, 0);
            sp.graphics.beginGradientFill( GradientType.LINEAR,
                [ 0x333333, color, color, color*0.9>>0, 0x000000 ],
                [ 1, 1, 1, 1, 1 ],
                [ 8, 64, 102, 204, 255],
                mtx,
                InterpolationMethod.RGB
            );
            sp.graphics.drawRect( 0, 0, 200, 10 );
            sp.graphics.endFill();
            _gradientMap.draw(sp);
            sp = null;    
        }
        
        
        
        private var _canvas:BitmapData;
        private var _center:Point;
        private function init():void{
            _camera = Camera.getCamera();
            _video = new Video(520,390);
            _video.attachCamera(_camera);
           _srcBmd = new BitmapData(520,390);
           _srcBmd.draw(_video);

            _center= new Point();
            _center.x = stage.stageWidth*0.5>>0;
            _center.y = stage.stageHeight*0.5>>0;
            
            _canvas  = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0 );
            addChild( new Bitmap(_canvas) );
            
            setup();
            addEventListener( Event.ENTER_FRAME, enterFrame);
            
            SWFProfiler.init( this );
        }
        private function enterFrame( e:Event ):void {
            _srcBmd.draw(_video);
            updateCalcuration();
            updateDrawing();
        }
        
        
        
        
        public function Sponsor() {
            addEventListener( Event.ADDED_TO_STAGE, addToStage );
        }
        private function addToStage (e:Event):void {
            init();
        }
    }
}