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

Leaves Particles

水中的な感じに
// forked from yd_niku's Fire Particles
// forked from yd_niku's forked from: Water Particles
// forked from yd_niku's Water Particles
// 水中的な感じに
package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.filters.*;
    import caurina.transitions.Tweener;
    [SWF(backgroundColor=0x003366, frameRate=40)]
    public class FlashTest extends Sprite {
        private var _particles:Array = [];
        private var _label:TextField;
        private var _bmp:BitmapData;
        private var _container:Sprite;
        private var _filter:BitmapFilter= new ColorMatrixFilter([
                                                                                    1, 0, 0, 0.5, 0,
                                                                                    0, 1, 0, 0.3, 0,
                                                                                    0, 0, 1, 0, 0,
                                                                                    0, 0, 0, 0.77, 0
                                                                                    ]);
        private static const O:Point = new Point();
        public function FlashTest() {
            _bmp = new BitmapData( stage.stageWidth, stage.stageHeight, true, 0x00FFFFFF );
            addChild( new Bitmap(_bmp) );

            _container = new Sprite();
            addChild( _container );

            var rect :Sprite= new Rect( stage.stageWidth, stage.stageHeight );
            addChild( rect  );
            rect.addEventListener( MouseEvent.MOUSE_DOWN, startWater );
            rect.addEventListener( MouseEvent.MOUSE_UP, stopWater  );
            rect.addEventListener( MouseEvent.CLICK, removeText );

            rect.buttonMode = true;
            rect.useHandCursor = true;
            addEventListener( Event.ENTER_FRAME, onUpdate );

            var t:TextField = new TextField();
            t.mouseEnabled = false;
            t.width = 200;
            t.defaultTextFormat = new TextFormat("_sans", 12, 0x333366 );
            t.text = "Please drag to create particles.";
            t.x = ( stage.stageWidth - t.width ) *0.5;
            t.y = ( stage.stageHeight- t.height ) *0.5;
            t.alpha = 0;
            _label = t;
            addChild( t );
            Tweener.addTween( t, { alpha : 1, time:2, delay:0.3, transition:"easeInOutSine" } );
        }
        private function removeText( e:Event ):void {
            e.currentTarget.removeEventListener( e.type, arguments.callee );
            if( _label ) Tweener.addTween( _label, { alpha : 0, time:2, delay:0.3, transition:"easeInOutSine", onComplete: onRemoveLabel } );
        }

        private function startWater ( e:Event ):void {
            addEventListener( Event.ENTER_FRAME, shot );
        }
        private function stopWater  ( e:Event ):void {
            removeEventListener( Event.ENTER_FRAME, shot );
        }
        private function shot( e:Event = null ) :void {
            var num:uint = 2;
            var p:Particle;
            var o:Vector3D = new Vector3D( mouseX, -10, mouseY );
            for( var i:int=0; i<num;++i ) {
                p = new Leaf(
                        Math.random()*16+1,
                        o.x +Math.random()*20-10, o.y+Math.random()*20-10, o.z,
                        Math.random()*100-50, Math.random()*100-50, 200 );
                _container.addChild(p);
                _particles.push( p );
            }
        }
        private function onRemoveLabel ():void {
            removeChild( _label );
            _label = null;
        }
        private function onUpdate( e:Event ):void  {
            var num:uint = _particles.length;
            var p:Particle;
            for( var i:int=0; i<num;++i ) {
                p = _particles[ i ] as Particle;
                if( p.checkLife() ) {
                    p.update();
                }
                else {
                    if( contains(p) ) _container.removeChild( p );
                }
            }
            _bmp.draw( _container );
            _bmp.applyFilter( _bmp, _bmp.rect, O, _filter );
        } 
    }
}
import flash.display.*;
import flash.geom.*;

class Particle extends Sprite {
    public static const G:Number = 1;
    public static const FRICTION_X:Number = 0.96;
    public static const FRICTION_Y:Number = 0.96;
    public static const FRICTION_Z:Number = 0.96;
    public var mass:Number=1;
    public var vx:Number=0;
    public var vy:Number=0;
    public var vz:Number=0;
    public static var LIMIT_Z:Number =200;
    public function Particle (
            smass:Number = 1,
            sx:Number=0,  sy:Number = 0, sz:Number = 0,
            svx:Number=0, svy:Number=0, svz:Number = 0
        ) {

        mass = smass;
        x = sx;
        y = sy;
        z = sz,
        vx = svx;
        vy = svy;
        vz = svz;
    }
    public function update():void {
        vy += G;
        vx *= FRICTION_X;
        vy *= FRICTION_Y;
        vz *= FRICTION_Z;
        x += vx*mass;
        y += vz*mass;
        z += vy*mass;

        if( z >= LIMIT_Z ) {
            mass = 0.05;
            vx *= 1.06;
            vz *= 1.06;
            vy *= 0.9;
            vy -= 0.4;
            var v:Vector3D = new Vector3D( vx, vy, vz );
            alpha = Math.min( 0.5, ( 100 - z + LIMIT_Z ) * 0.005 );
            scaleX = scaleY = 1.5 * alpha;
        }
        else {
            rotationX +=mass*10;
            rotationY +=mass*4;
        }
    }

    public function checkLife() :Boolean {
        //var v:Vector3D = new Vector3D( vx, vy, vz );
        return  z < 350;
    }
}

class Leaf extends Particle {
    public function Leaf( weight:Number, sx:Number=0, sy:Number = 0, sz:Number = 0, svx:Number=0, svy:Number=0, svz:Number=0 ) {
        super( 0.05, sx, sz, sy, svx, svz, svy );
        graphics.lineStyle( 0, 0x99cc33, 0.8+Math.random()*0.2 );
        graphics.beginFill( 0x99cc99, Math.random()*0.2 + 0.2 );
        graphics.drawCircle( 0, 0, weight );
        graphics.endFill();
    }
}
class Rect extends Sprite {
    public function Rect( w:uint= 100, h:uint = 100 ) {
        graphics.beginFill( 0, 0 );
        graphics.drawRect( 0, 0, w, h );
        graphics.endFill();
    }
}