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

キラメキのようななにか

Get Adobe Flash player
by soundkitchen 01 Mar 2009
package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BitmapFilter;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;
    import flash.geom.Point;

    [SWF(frameRate=60, width=500, height=500, backgroundColor=0x000000)]
    public class Main extends Sprite
    {
        private static var _zero:Point = new Point();

        private var _canvas:Shape;
        private var _film:BitmapData;
        private var _filter:BitmapFilter;
        private var _mouseDownFlag:Boolean;
        private var _particles:Array;

        public function Main()
        {
            addEventListener(Event.ADDED_TO_STAGE, initialize);
        }

        private function initialize(evt:Event):void
        {
            removeEventListener(evt.type, arguments.callee);

            Particle.initialize(stage);

            _particles = [];
            _mouseDownFlag = false;

            _canvas = new Shape();
            _filter = new BlurFilter(6, 6, BitmapFilterQuality.MEDIUM);
            _film = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
            addChild(new Bitmap(_film));

            addEventListener(Event.ENTER_FRAME, step);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
        }

        private function step(evt:Event):void
        {
            var i:int,
                g:Graphics,
                p:Particle;

            if (_mouseDownFlag)
            {
                for (i=0; i<10; i++)
                {
                    addParticle();
                }
            }

            g = _canvas.graphics;
            g.clear();
            for each (p in _particles)
            {
                p.update();

                g.beginFill(p.color);
                g.drawCircle(p.x, p.y, 1);
                g.endFill();

                if (!p.isAlive)
                {
                    i = _particles.indexOf(p);
                    _particles.splice(i, 1);
                }
            }

            _film.lock();
            _film.applyFilter(_film, _film.rect, _zero, _filter);
            _film.draw(_canvas, null, null, BlendMode.ADD);
            _film.unlock();
        }

        private function mouseDownHandler(evt:MouseEvent):void
        {
            _mouseDownFlag = true;
        }

        private function mouseUpHandler(evt:MouseEvent):void
        {
            _mouseDownFlag = false;
        }

        private function addParticle():void
        {
            var i:int,
                len:Number,
                angle:Number;

            len = Math.random() * 5;
            angle = Math.random() * Math.PI * 2;

            _particles.push(new Particle(mouseX, mouseY, len, angle));
        }
    }
}

import flash.display.Stage;
import flash.geom.Rectangle;

class Particle
{
    private static var _frameRate:Number;
    private static var _stageRect:Rectangle;

    private var _x:Number;
    private var _y:Number;
    private var _tick:uint;
    private var _len:Number;
    private var _angle:Number;
    private var _energy:Number;

    public static function initialize(stage:Stage):void
    {
        _frameRate = stage.frameRate;
        _stageRect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
    }

    public function get x():Number
    {
        return _x;
    }

    public function get y():Number
    {
        return _y;
    }

    public function get color():uint
    {
        return (_energy * 0xFD) << 16|(_energy * 0xFE) << 8|(_energy * 0xAE);
    }

    public function get isAlive():Boolean
    {
        return _stageRect.contains(x, y);
    }

    function Particle(x:Number, y:Number, len:Number, angle:Number)
    {
        _x = x;
        _y = y;
        _len = len;
        _angle = angle;
        _tick = 0;
        _energy = 1;
    }

    public function update():void
    {
        _energy *= .98;
        _x += _len * Math.cos(_angle);
        _y += 9.8 * (++_tick / _frameRate) + _len * Math.sin(_angle);
    }
}