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

Rosace | Eye

/**
 * Copyright FLASHMAFIA ( http://wonderfl.net/user/FLASHMAFIA )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rPSF
 */

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.utils.getTimer;

    [SWF (width = '465', height = '465', backgroundColor = '0x000000', frameRate = '32')]
    public class Rosace extends Sprite
    {
        private var w : uint = 465;
        private var h : uint = 465;
        private var _rect : Rectangle = new Rectangle(0, 0, w, h);
        private var _bmd : BitmapData = new BitmapData(w, h, false, 0);
        private var _buf : Vector.<uint> = new Vector.<uint>(w * h, true);
        private var lut_c : Vector.<int> = new Vector.<int>(w * h, true);
        private var lut_s : Vector.<int> = new Vector.<int>(w * h, true);
        private var lut_d : Vector.<int> = new Vector.<int>(w * h, true);

        public function Rosace()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;

            graphics.beginFill(0, 1);
            graphics.drawRect(0, 0, w, h);

            addChild(new Bitmap(_bmd));

            var n : uint = _buf.length;
            while (--n > -1)
            {
                var px : Number = -1 + 2 * (n % w) / w;
                var py : Number = -1 + 2 * (n / w) / h;
                var d : Number = Math.sqrt(px * px + py * py);

                var a : Number = Math.atan2(px, py);

                lut_c[n] = h * Math.cos(a) / d;
                lut_s[n] = w * Math.sin(a) / d;
                lut_d[n] = d * ((w >> 2) + (h >> 2));
                if (lut_d[n] > 0xFF) lut_d[n] = 0xFF;
            }

            addEventListener(Event.ENTER_FRAME, oef);
        }

        private function oef(e : Event) : void
        {
            var d : Number = getTimer() * 0.00075;
            var px : int = Math.sin(d) * 750;
            var py : int = Math.cos(d) * 750;

            var n : uint = _buf.length;
            while (--n > -1)
            {
                var pz : int = (lut_c[n] - px ^ lut_s[n] + py) & w;
                var c : uint = lut_d[n];
                _buf[n] = ((pz & c) << 24) | ((pz & c) << 16) | ((pz & c) << 8) | (pz & c);
            }

            _bmd.setVector(_rect, _buf);
        }
    }
}