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

花火 from: そして弾幕へ

// forked from munegon's そして弾幕へ from: ぱーてぃくる
// forked from munegon's ぱーてぃくる
// write as3 code here..
package {
    import caurina.transitions.Tweener;
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    
    public class FireFlower extends Sprite {
        private var SPEED_FO:Number = 0.9;
        
        private var canvas_bd:BitmapData;
        private var ctf:ColorTransform;
        private var temp:Sprite;
        private var tf:TextField;
        
        public function FireFlower () {
            addEventListener( Event.ADDED_TO_STAGE, added );
        }
        
        private function added( e:Event ):void {
            if ( e.target == this ) {
                removeEventListener( e.type, arguments.callee );
                
                stage.quality = StageQuality.LOW;
                stage.frameRate = 60;
                
                setup();   
            }    
        }

        
        private function setup():void {
            canvas_bd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
            addChild( new Bitmap( canvas_bd ) );
            
            ctf = new ColorTransform( SPEED_FO, SPEED_FO, SPEED_FO, 1.0 );
            temp = new Sprite();
            
            tf = new TextField();
            tf.x = 5;
            tf.y = 5;
            tf.textColor = 0xffffff;
            tf.mouseEnabled = false;
            addChild( tf );
            
            addEventListener( Event.ENTER_FRAME, update, false, 10 );
            Tweener.addTween( this, { time:0.5, onComplete:createFlower } );
        }
        
        private function update( e:Event ):void {
            canvas_bd.unlock();
            canvas_bd.lock();
            canvas_bd.colorTransform( canvas_bd.rect, ctf );
            
            tf.text = temp.numChildren.toString();
        }
        
        private function createFlower():void {
            var cx:Number = stage.stageWidth/4 + stage.stageWidth/2*Math.random();
            var cy:Number = stage.stageHeight/4 + stage.stageHeight/2*Math.random();
            var color:uint = [0xff6666, 0xffff66, 0x66ff66, 0x66ffff][Math.floor(3*Math.random())];
            
            for ( var i:int = 0; i < 256; ++i ) {
                fire( cx, cy, color );
            }
            
            Tweener.addTween( this, { time:5+5*Math.random(), onComplete:createFlower } );
        }
        
        private function fire( cx:Number, cy:Number, color:uint ):void {
            var x:Number = cx;
            var y:Number = cy;
            var v:Number = 2*Math.random();
            var r:Number = 2*Math.PI * Math.random();
            
            var vx:Number = v * Math.cos( r );
            var vy:Number = v * Math.sin( r );
            var vr:Number = 0.02;
            var dir:Number = 1 - 2*Math.floor( 2*Math.random() );
            
            var count:int = 0;
            var size:Number = 1;
            var rect:Rectangle = new Rectangle( x, y, 2*size, 2*size );
            
            var bullet:Sprite = new Sprite();
            temp.addChild( bullet );
            
            bullet.addEventListener( Event.ENTER_FRAME, function( e:Event ):void {
                vy += 0.01;
                x += vx;
                y += vy;
                rect.x = x - size;
                rect.y = y - size;
                
                count++;
                
                if ( Math.random() < Math.max( 0.05, 1-count/100 ) ) {
                    canvas_bd.fillRect( rect, color );
                }
               
                if ( ( count > 120 ) || ( canvas_bd.rect.contains( x, y ) == false ) ) {
                    bullet.removeEventListener( e.type, arguments.callee );
                    bullet.graphics.clear();
                    temp.removeChild( bullet );
                    bullet = null;
                }
            }, false, 1 );
        }
    }
}