Beautifl - Flash Gallery

Thumbnail : Julia
Julia
rect 2009-08-28 All rights reserved

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

//
// Julia
// by rect (http://blog.r3c7.net/)
//

package
{
    import flash.events.Event;
    import flash.display.*;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.geom.ColorTransform;
    import flash.utils.getTimer;
    import flash.utils.ByteArray;
    
    import frocessing.color.ColorHSV;

    [SWF(backgroundColor="#000000")]
    
    public class main extends Sprite
    {
        private var w:uint = 128;
        private var h:uint = 128;
        private var pixels:uint = 0;
        
        private var cont:Bitmap;
        private var buffer:BitmapData;
        private var zero:Point = new Point(0,0);
        private var byte:ByteArray;

        private var zoom:Number = 1;
        private var mx:Number = 0;
        private var my:Number = 0;
        private var maxIteration:int = 128;
        private var rot:Number = 179;

        public function main():void
        {
            stage.frameRate = 30;
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.LOW;

            buffer = new BitmapData(w, h, true, 0);
            byte = new ByteArray();
            byte.position = 0;

            pixels = w * h;

            var bmp:BitmapData = new BitmapData(w, h, true, 0);
            cont = new Bitmap(bmp);
            addChild(cont);
            
            cont.width = stage.stageWidth;
            cont.height = stage.stageHeight;
            cont.x = (stage.stageWidth - cont.width) / 2;
            cont.y = (stage.stageHeight - cont.height) / 2;

            addEventListener(Event.ENTER_FRAME, update);
        }

        private function update(e:Event):void
        {
            var targetBmd:BitmapData = cont.bitmapData;
            var bytes:ByteArray = byte;
            bytes.position = 0;

            rot += 1;
            zoom = 51 + Math.sin(rot * -0.017453292519943295) * -50;

            var pr:Number = -0.7;
            var pi:Number = 0.270115;
            for (var j:uint = 0; j < pixels; j++)
            {
                var x:int = (j & 0x7F);
                var y:int = (j / w) >> 0;
                var newRe:Number = 1.5 * (x - 64) / (zoom * 64) + mx;
                var newIm:Number = (y - 64) / (zoom * 64) + my;
                var oldRe:Number = 0;
                var oldIm:Number = 0;
                var i:int = 0;
                for(i = 0; i < maxIteration; i++)
                {
                    oldRe = newRe;
                    oldIm = newIm;
                    newRe = oldRe * oldRe - oldIm * oldIm + pr;
                    newIm = 2 * oldRe * oldIm + pi;
                    if((newRe * newRe + newIm * newIm) > 4) break;
                }
                var hsv:ColorHSV = new ColorHSV((i + 192) & 255, 0.9, (240 * Number(i < maxIteration))*0.01, (240 * Number(i < maxIteration))*0.01);
                var rgb:uint = hsv.value32;
                bytes.writeUnsignedInt(rgb);
            }

            bytes.position = 0;
            buffer.lock();
            buffer.setPixels(buffer.rect, bytes);
            buffer.unlock();
            targetBmd.colorTransform( targetBmd.rect, new ColorTransform(1, 1, 1, 1, -1, -1, -1, -16));
            targetBmd.copyPixels(buffer, buffer.rect, zero, null, null, true);
        }
    }
}