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: LightCircle (2)

LightCircle (2)

[AS3.0] LightCircleクラスだ! (2)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1153
Get Adobe Flash player
by Thy 08 Sep 2010
/**
 * Copyright Thy ( http://wonderfl.net/user/Thy )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/muQR
 */

// forked from ProjectNya's LightCircle (2)
////////////////////////////////////////////////////////////////////////////////
// LightCircle (2)
//
// [AS3.0] LightCircleクラスだ! (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1153
////////////////////////////////////////////////////////////////////////////////

package {
    import flash.geom.Matrix;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.display.BitmapData;

    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;

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

    public class Main extends Sprite {
        private var light:LightCircle;
        private var colors:Array
        private var data:BitmapData, bitmap:Bitmap;
        private var circles_data:Vector.<BitmapData>;

        public function Main() {
            init();
        }

        private function init():void {
            var rect:Rectangle = new Rectangle(0, 0, 465, 465);
            data = new BitmapData(rect.width,rect.height,false,0);
            bitmap = new Bitmap(data, "auto", true);
            circles_data = new Vector.<BitmapData>();
            addChild(bitmap);
            colors = new Array();
            colors.push({h: 270, s: 0.6, v: 1});
            colors.push({h: 300, s: 0.8, v: 1});
            colors.push({h: 0, s: 0.8, v: 1});
            colors.push({h: 60, s: 1, v: 1});
            colors.push({h: 76, s: 0.8, v: 1});
            colors.push({h: 90, s: 1, v: 1});
            colors.push({h: 100, s: 1, v: 0.8});
            colors.push({h: 180, s: 1, v: 1});
            colors.push({h: 200, s: 1, v: 1});
            colors.push({h: 220, s: 1, v: 1});
            light = new LightCircle(rect, colors);
            var m:Matrix = new Matrix();
            var n:int = -1;
            var circle:Circle;
            var d:BitmapData;
            while(++n < colors.length)
            {
                circle = light.circleList[n];
                m.tx = circle.width;
                m.ty = circle.height;
                d = new BitmapData(circle.width*2, circle.height*2, false, 0);
                d.draw(circle, m);
                circles_data.push(d);
            }
            addEventListener(Event.ENTER_FRAME, ef);
        }
        
        private function ef(e:Event):void
        {
            light.move();
            var circle:Circle;
            var d:BitmapData;
            var m:Matrix = new Matrix();
            data.lock();
            data.fillRect(data.rect, 0);
            var n:int = -1;
            while(++n < colors.length)
            {
                circle = light.circleList[n];
                m.tx = circle.x - circle.width;
                m.ty = circle.y - circle.height;
                d = circles_data[n];
                data.draw(d, m, null, BlendMode.ADD);
            }
            data.unlock();

        }
    }
}


//////////////////////////////////////////////////
// LightCircleクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.display.BlendMode;
import flash.filters.ColorMatrixFilter;
import frocessing.color.ColorHSV;

class LightCircle extends Sprite {
    private var rect:Rectangle;
    private var colors:Array;
    private var circles:uint;
    public var circleList:Array;
    private var colorMatrix:ColorMatrixFilter;
    private var matrix:Array;

    public function LightCircle(r:Rectangle, c:Array) {
        rect = r;
        colors = c;
        circles = colors.length;
        init();
    }

    private function init():void {
        circleList = new Array();
        for (var n:uint = 0; n < circles; n++) {
            var hue:uint = colors[n].h;
            var saturation:Number = colors[n].s;
            var value:Number = colors[n].v;
            var color:ColorHSV = new ColorHSV(hue, saturation, value);
            var circle:Circle = new Circle(100);
            circle.color = color.value;
            circle.blendMode = BlendMode.ADD;
            circleList.push(circle);
        }
        colorMatrix = new ColorMatrixFilter();
        matrix = new Array();
        matrix = [1, 0, 0, 0, 0,
                  0, 1, 0, 0, 0,
                  0, 0, 1, 0, 128,
                  0, 0, 0, 1, 0];
        colorMatrix.matrix = matrix;
        filters = [colorMatrix];
        create();
    }
    private function create():void {
        for (var n:uint = 0; n < circles; n++) {
            var circle:Circle = circleList[n];
            circle.x = Math.random()*rect.width;
            circle.y = Math.random()*rect.height;
            circle.vx = Math.random()*8 - 4;
            circle.vy = Math.random()*8 - 4;
            addChild(circle);
        }
    }
    public function start():void {
        addEventListener(Event.ENTER_FRAME, move, false, 0, true);
    }
    public function stop():void {
        removeEventListener(Event.ENTER_FRAME, move);
    }
    public function move(evt:Event = null):void {
        for (var n:uint = 0; n < circles; n++) {
            var circle:Circle = circleList[n];
            if (circle.x < rect.left || circle.x > rect.right) circle.vx = - circle.vx;
            if (circle.y < rect.top || circle.y > rect.bottom) circle.vy = - circle.vy;
            circle.x += circle.vx;
            circle.y += circle.vy;
        }
    }


}


//////////////////////////////////////////////////
// Circleクラス
//////////////////////////////////////////////////

import flash.display.Shape;
import flash.filters.BlurFilter;

class Circle extends Shape {
    private var radius:uint = 100;
    private var rgb:uint = 0xFFFFFF;
    private var blur:BlurFilter
    public var vx:Number = 0;
    public var vy:Number = 0;

    public function Circle(r:uint) {
        radius = r;
        blur = new BlurFilter(radius*0.5, radius*0.5, 3);
        draw();
    }

    private function draw():void {
        graphics.clear();
        graphics.beginFill(rgb);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
        var blur:BlurFilter = new BlurFilter(50, 50, 3);
        filters = [blur];
    }
    public function set color(c:uint):void {
        rgb = c;
        draw();
    }

}