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: forked from: Water 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="#FFFFFF", 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.1, 0,
                                                                                    0, 1, 0, 0.2, 0,
                                                                                    0, 0, 1, 0, 0,
                                                                                    0, 0, 0, 0.5, 0
                                                                                    ]);
        private static const O:Point = new Point();
		private var _filter2:GlowFilter = new GlowFilter( 0x99ccff, 1, 15, 15, 1 );
        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 = 3;
            var p:Particle;
            var o:Vector3D = new Vector3D( mouseX, mouseY, -10 );
            for( var i:int=0; i<num;++i ) {
                p = new Water(
                        Math.random()*6+1,
                        o.x +Math.random()*6-3, o.y+Math.random()*6-3, o.z,
                        Math.random()*5-10, Math.random()*-6-20, 15 );
                _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 );
            _bmp.applyFilter( _bmp, _bmp.rect, O, _filter2 );
        } 
    }
}
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_Y:Number = 500;
    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 += vy*mass;
        z += vz*mass;

        if( y >= LIMIT_Y) {
            vy *= -0.5;
            y += vy;
        }
    }
    public function checkLife() :Boolean {
        var v:Vector3D = new Vector3D( vx, vy, vz );
        return  v.length > 1;
    }
}

class Water extends Particle {
    public function Water( weight:Number, sx:Number=0, sy:Number = 0, sz:Number = 0, svx:Number=0, svy:Number=0, svz:Number=0 ) {
        super( weight*0.05+0.4, sx, sy, sz, svx, svy, svz );
        graphics.beginFill( 0x88bbff, Math.random() );
        //graphics.beginFill( 0xFFFFFF, Math.random() );
        graphics.drawCircle( 0, 0, weight );
		graphics.beginFill( 0xffffff, 0.1);
		graphics.drawCircle( weight/4, weight/4, weight/2 );
        graphics.endFill();
		this.blendMode = BlendMode.HARDLIGHT;
    }
}
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();
    }
}