Beautifl - Flash Gallery

Thumbnail : [朝ワン] オーロラ3
[朝ワン] オーロラ3
bkzen 2009-08-30 MIT License

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

package  
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.utils.getTimer;
    import net.hires.debug.Stats;
    
    /**
     * 朝ワン(∪^ω^)ワン またまた別バージョン
     * 何かきれいなのできた。
     * @author jc at bk-zen.com
     */
    [SWF (backgroundColor = "0x0", frameRate = "60", width = "465", height = "465")]
    public class Asawon13 extends Sprite
    {
        private var bmd: BitmapData;
        private var first: Particle;
        private var prev: Particle;
        private var cnt: int = 0;
        private var colCnt: int = 0;
        private var forceMap:BitmapData;
        private var seed: int;
        private var arr: Array;
        private var point1: Point = new Point();
        private var point2: Point = new Point();
        private var basePoint: Point = new Point();
        private var blur: BlurFilter = new BlurFilter(2, 2);
        private var baseMatrix: Matrix = new Matrix();
        private var canvas: BitmapData;
        private var colorTf: ColorTransform = new ColorTransform(1, 1, 1, 1, -1, -1, -1);
        
        public function Asawon13() 
        {
                Wonderfl.capture_delay( 30 );
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e: Event = null): void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            canvas = new BitmapData(465, 465, false, 0x0);
            addChild(new Bitmap(bmd = canvas.clone()));
            //addChild(new Stats());
            forceMap = new BitmapData(10, 10, false);
            forceMap.perlinNoise(20, 20, 4, seed = Math.random() * 0xFFFF, false, true, 3, false, arr = [point1, point2]);
            addEventListener(Event.ENTER_FRAME, loopA);
        }
        
        private function loopA(e: Event ): void 
        {
            cnt ++;
            if (first == null) first = prev = new Particle();
            else prev = prev.next = new Particle();
            prev.color = getColor(colCnt / 10)
            loopB();
            if (cnt == 5000) 
            {
                removeEventListener(Event.ENTER_FRAME, loopA);
                addEventListener(Event.ENTER_FRAME, loopB);
            }
        }
        
        private function loopB(e: Event = null): void 
        {
            var p: Particle = first, col: uint = forceMap.getPixel(5, 5), r: Number = (( col >> 16 & 0xff) - 128) * 0.0004, g: Number = (( col >>  8 & 0xff) - 128) * 0.0004;
            colCnt = (getTimer()) % 3600;
            col = getColor(colCnt / 10);
            if (colCnt % 2 == 0) point1.x = point2.y ++;
            forceMap.perlinNoise(20, 20, 4, seed, false, true, 3, false, arr);
            canvas.lock();
            while ((p = p.next) != null)
            {
                p.x += (p.vx = p.vx * (0.95 + p.r + (p.a * 0.0005)) + r);
                p.y += (p.vy = p.vy * (0.95 + p.r + (p.a * 0.0005)) + g);
                canvas.setPixel(p.x, p.y, p.color);
                p.a ++;
                if (p.a > 360) 
                {
                    p.x = p.y = 232;
                    p.vx = p.vy = p.a = 0;
                    p.color = col;
                }
            }
            canvas.colorTransform(bmd.rect, colorTf);
            canvas.unlock();
            bmd.lock();
            bmd.draw(canvas, baseMatrix, null, BlendMode.ADD);
            bmd.applyFilter(bmd, bmd.rect, basePoint, blur);
            bmd.colorTransform(bmd.rect, colorTf);
            bmd.unlock();
        }
        private function getColor(h: Number): uint
        {
            var c: int = h < 180 ? 0x2FD - (h * 4.25) : (h - 180) * 4.25;
            var r: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            c = h < 120 ? h * 4.25 + 0xFF : h < 300 ? 0x1FE - (h - 180) * 4.25 : 0;
            var g: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            c = h < 120 ? 0 : h < 240 ? (h - 120) * 4.25 + 0xFF : 0x1FE - (h - 300) * 4.25;
            var b: uint = (c > 0x1FE ? 0xFF : c < 0xFF ? 0 : c - 0xFF);
            return (r << 16) | (g << 8) | b;
        }
    }
}
class Particle
{
    public var x: Number = 232;
    public var y: Number = 232;
    public var a: Number = 0;
    public var r: Number = Math.random() * 0.01;
    public var vx: Number = 0;
    public var vy: Number = 0;
    public var next: Particle;
    public var color: uint;
}