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

LightWater [BitmapData版]

////////////////////////////////////////////////////////////////////////////////
// LightWater [BitmapData版]
//
//  [AS3.0] 燃える火・きらめく星・流れる水
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1047
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 10 Sep 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b1P9
 */

////////////////////////////////////////////////////////////////////////////////
// LightWater [BitmapData版]
//
//  [AS3.0] 燃える火・きらめく星・流れる水
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1047
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import net.hires.debug.Stats;

    [SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var water:LightWater;
        private var playing:Boolean = true;

        public function Main() {
            //Wonderfl.capture_delay(4);
            init();
            addChild(new Stats());
        }

        private function init():void {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            var rect:Rectangle = new Rectangle(0, 0, 465, 465);
            water = new LightWater(rect);
            addChild(water);
            var area:Rectangle = new Rectangle(32, 80, 400, 64);
            water.setup(8, area);
            water.color = [0x3399FF, 0x66CCFF, 0x99FFFF];
            water.start();
            stage.addEventListener(MouseEvent.CLICK, click, false, 0, true);
        }
        private function click(evt:MouseEvent):void {
            playing = !playing;
            if (playing) {
                water.start();
            } else {
                water.stop();
            }
        }

    }

}


import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.BlendMode;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.easing.Quad;
import org.libspark.betweenas3.events.TweenEvent;

class LightWater extends Sprite {
    private var rect:Rectangle;
    private var bitmapData:BitmapData;
    private var bitmap:Bitmap;
    private static var ids:Array = [0, 0, 0, 0, 0, 1, 1, 2, 3];
    private var colors:Array;
    private var unit:uint;
    private var particles:Array;
    private var area:Rectangle;
    private static var targetPos:int = 500;

    public function LightWater(r:Rectangle) {
        rect = r;
        mouseChildren = false;
        init();
    }

    private function init():void {
        bitmapData = new BitmapData(rect.width, rect.height, false, 0xFF000000);
        bitmap = new Bitmap(bitmapData);
        addChild(bitmap);
        particles = new Array();
    }
    public function setup(n:uint, a:Rectangle):void {
        unit = n;
        area = a;
    }
    public function set color(list:Array):void {
        colors = list;
        colors.push(0xFFFFFF);
    }
    public function start():void {
        addEventListener(Event.ENTER_FRAME, update, false, 0, true);
    }
    public function stop():void {
        removeEventListener(Event.ENTER_FRAME, update);
    }
    private function update(evt:Event):void {
        create();
        draw();
    }
    private function create():void {
        for (var n:uint = 0; n < unit; n++) {
            var id:uint = ids[Math.floor(Math.random()*(ids.length+1))];
            var water:Particle = new Particle(colors[id]);
            water.x = area.x + Math.random()*area.width;
            water.y = area.y + Math.random()*area.height;
            particles.push(water);
            var itween:ITween = BetweenAS3.serial(
                BetweenAS3.tween(water, {alpha: 1, scaleY: 0.75}, {alpha: 0, scaleY: 0.5}, 0.2, Quad.easeOut), 
                BetweenAS3.to(water, {y: targetPos, alpha: 0, scaleY: 1}, 0.8, Quad.easeIn)
            );
            itween.addEventListener(TweenEvent.COMPLETE, complete, false, 0, false);
            itween.play();
        }
    }
    private function complete(evt:TweenEvent):void {
        evt.target.removeEventListener(TweenEvent.COMPLETE, complete);
        var water:Particle = evt.target.getTweenAt(0).target;
        particles.shift();
    }
    private function draw():void {
        bitmapData.lock();
        bitmapData.fillRect(rect, 0xFF000000);
        for (var n:uint = 0; n < particles.length; n++) {
            var water:Particle = particles[n];
            var matrix:Matrix = new Matrix();
            matrix.translate(water.x, water.y);
            var colorTrans:ColorTransform = new ColorTransform();
            colorTrans.color = water.color;
            colorTrans.alphaMultiplier = water.alpha;
            bitmapData.draw(water, matrix, colorTrans, BlendMode.ADD);
        }
        bitmapData.unlock();
    }

}


import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;

class Particle extends Shape {
    private static var _width:uint = 40;
    private static var _height:uint = 80;
    private static var yOffset:int = 20;
    private static var bColor:uint = 0xFFFFFF;
    public var color:uint;

    public function Particle(c:uint) {
        color = c;
        draw();
    }

    private function draw():void {
        var colors:Array = [bColor, bColor];
        var alphas:Array = [1, 0];
        var ratios:Array = [0, 255];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(_width, _height, 0, -_width*0.5, -_height*0.5+yOffset);
        graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        graphics.drawEllipse(-_width*0.5, -_height*0.5+yOffset, _width, _height);
        graphics.endFill();
    }

}