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

MidPoint Of No Return

MidPoint Circles Optimization ~

+ Other Bitwise Calculations / Tricks,
more or less relevant, for the sake of the experiment, really.
/**
 * Copyright FLASHMAFIA ( http://wonderfl.net/user/FLASHMAFIA )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lx3t
 */

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Rectangle;

    [SWF(width = '512', height = '512')]
    public class MidPointOfNoReturn extends Sprite
    {
        /* */
        private const SW : int = 1 << 9;
        private const SH : int = 1 << 9;
        /* */
        private var _buff : Vector.<uint>;
        private var _bmd : BitmapData;
        private var _cx : int;
        private var _cy : int;
        private var _t : int;

        function MidPointOfNoReturn() {
            
            /* */

            stage.stageFocusRect = mouseEnabled = mouseChildren = tabEnabled = tabChildren = false;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.fullScreenSourceRect = new Rectangle(0, 0, SW, SH);
            stage.quality = StageQuality.LOW;
            stage.frameRate = 64;
            opaqueBackground = 0x0;

            /* */

            var bm : Bitmap = new Bitmap(_bmd = new BitmapData(SW, SH, false, 0x0));
            bm.opaqueBackground = 0x0;
            addChild(bm);

            _buff = _bmd.getVector(_bmd.rect);
            _buff.fixed = true;

            /* */

            _t = 0;

            trace('0xFF: ' + (0xFF));

            addEventListener(Event.ENTER_FRAME, oef);
        }

        private function oef(e : Event) : void {
            /* */

            _cx += ((int(stage.mouseX) << 1) - _cx) >> 5;
            _cy += ((int(stage.mouseY) << 1) - _cy) >> 5;

            /* */

            _t++;
            _t &= 511;

            var t1 : int = (0xFF - (_t & 0xFE));
            var t2 : int = ((_t + 0x22) & 0xFE);
            var t3 : int = (0xFF - ((_t + 0x80) & 0xFE));

            drawMPC(32, ((((t1 << 1) & 0xFF) << 16) | (((t1 << 1) & 0xFF) << 8) | (((t1 << 1) & 0xFF) >> 1)), t1);
            drawMPC(16, ((((t2 << 1) & 0xFF) << 16) | (((t2 << 1) & 0xFF) << 8) | (((t2 << 1) & 0xFF) >> 1)), t2);
            drawMPC(16, ((((t3 << 1) & 0xFF) << 16) | (((t3 << 1) & 0xFF) << 8) | (((t3 << 1) & 0xFF) >> 1)), t3);

            /* */

            _bmd.setVector(_bmd.rect, _buff);
        }

        private function drawMPC(gurf : uint, color : uint, radius : int) : void {
            while (gurf-- > 2) {
                drawMidPointCircle(_cx, _cy, gurf + radius, color);
            }
        }

        private function drawMidPointCircle(cx : int, cy : int, r : int, c : uint) : void {
            /* */

            _buff[((cy & 511) << 9) + ((cx - r) & 511)] = c;
            _buff[((cy & 511) << 9) + ((cx + r) & 511)] = c;
            _buff[(((cy - r) & 511) << 9) + (cx & 511)] = c;
            _buff[(((cy + r) & 511) << 9) + (cx & 511)] = c;

            var t : int;
            var d : int = 1 - r;
            var de : int = 3;
            var dse : int = 5 - (r << 1);

            /* 1/8TH CIRCLE */

            while (r > t) {
                if (d < 0) {
                    d += de;
                    de++;
                    de++;
                    dse++;
                    dse++;
                } else {
                    d += dse;
                    de++;
                    de++;
                    dse++;
                    dse++;
                    dse++;
                    dse++;

                    r--;
                }

                t++;

                _buff[(((cy - r) & 511) << 9) + ((cx - t) & 511)] = c;
                _buff[(((cy - t) & 511) << 9) + ((cx - r) & 511)] = c;
                _buff[(((cy - t) & 511) << 9) + ((cx + r) & 511)] = c;
                _buff[(((cy - r) & 511) << 9) + ((cx + t) & 511)] = c;
                _buff[(((cy + r) & 511) << 9) + ((cx - t) & 511)] = c;
                _buff[(((cy + t) & 511) << 9) + ((cx - r) & 511)] = c;
                _buff[(((cy + t) & 511) << 9) + ((cx + r) & 511)] = c;
                _buff[(((cy + r) & 511) << 9) + ((cx + t) & 511)] = c;
            }
        }
    }
}