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

The color is colorfully changed! カラフルになった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="#000000", 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, 1, 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();
        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, 0xffffff );
            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()*40+1,
                        o.x +Math.random()*6-3, o.y+Math.random()*6-3, o.z,
                        Math.random()*40-10, Math.random()*-40-20, 0 );
                _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_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.lineStyle( 0, Math.random() * 0xffff00, 0.4+Math.random()*0.2 );
        graphics.beginFill( Math.random() * 0xffff00, Math.random()*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();
    }
}