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

BITFIRE | 01

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

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.IBitmapDrawable;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;
    import flash.filters.GlowFilter;
    import flash.geom.ColorTransform;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    [SWF(width = "465", height = "465")]
    public class BitFire2 extends Sprite
    {
        private const NUM_P : int = 1 << 15;
        /* */
        private var ppp : Vector.<Particle>;
        private var bmd : BitmapData;
        private var srcBmd : BitmapData;
        private var buf : Vector.<uint>;
        private var src : Sprite;
        private var tf : TextField;
        private var ct : ColorTransform;
        private var blur : BlurFilter;
        private var fcnt : int;
        private var pcnt : int;
        private var ccnt : int;

        function BitFire2()
        {
            stage.stageFocusRect = mouseEnabled = tabEnabled = tabChildren = false;
            stage.scaleMode = "noScale";
            stage.align = "TL";
            stage.quality = "low";
            stage.frameRate = 64;
            opaqueBackground = 0x0;

            bmd = new BitmapData(512, 512, false, 0x0);
            srcBmd = new BitmapData(512, 512, false, 0xFF4400);
            buf = new Vector.<uint>(512 * 512, true);

            var bm : Bitmap = new Bitmap(bmd);
            bm.x = bm.y = (465 - 512) >> 1;
            bm.opaqueBackground = 0x0;
            addChild(bm);

            /* p */

            ppp = new Vector.<Particle>(NUM_P, true);

            var n : uint = NUM_P;
            while (n-- != 0) //
            {
                var p : Particle = new Particle();

                var f : Number = n / NUM_P;
                var a : Number = (2 * 6.283185307179586) * f;
                var nn : uint = (n & 127);

                p.tx = p.ty = p.x = p.y = 256;

                p.ex = 256 + (512 - 128 + nn) * Math.cos(a);
                p.ey = 256 + (512 - 128 + nn) * Math.sin(a);

                p.fmax = (nn + (((Math.abs(p.ex - 256) >> 0) & 255) + ((Math.abs(p.ey - 256) >> 0) & 255)) & 127) >> 2;

                // p.fmax = Math.sqrt((p.ex - 256) * (p.ex - 256) + (p.ey - 256) * (p.ey - 256)) >> 2;
                // p.fmax = ((Math.sqrt((p.ex - 256) * (p.ex - 256) + (p.ey - 256) * (p.ey - 256)) >> 0) & 63);

                p.fcnt = -p.fmax;
                p.finc = 1;

                trace('p.fmax: ' + (p.fmax));

                ppp[n] = p;
            }

            /* << to be atomized >> */

            tf = new TextField();
            tf.defaultTextFormat = new TextFormat("_sans", 222, 0xFFFFFF, true);
            tf.autoSize = TextFieldAutoSize.LEFT;

            src = new Sprite();
            src.addChild(tf);

            ct = new ColorTransform(1.0, 1.0, 1.0, 0.94);
            blur = new BlurFilter(4.0, 4.0, BitmapFilterQuality.LOW);

            /* go */

            addEventListener(Event.ENTER_FRAME, oef);
        }

        private function oef(e : Event) : void //
        {
            fcnt++;

            if ((fcnt & 127) == 1)//
            {
                ccnt++;

                tf.text = (((ccnt & 31) < 10) ? "0" : "") + String(ccnt & 31);
                tf.x = (512 - tf.width) / 2;
                tf.y = (512 - tf.height) / 2;
                tf.textColor = 0xFF4000;
                tf.filters = [new GlowFilter(tf.textColor, 1.0, 4.0, 4.0, 2, 3)];

                atomize(src);
            }

            bmd.lock();
            bmd.colorTransform(bmd.rect, ct);
            bmd.applyFilter(bmd, bmd.rect, bmd.rect.topLeft, blur);
            buf = bmd.getVector(bmd.rect);

            // n = buf.length;
            // while (--n != 0) buf[n] = 0x0;

            var n : uint = NUM_P;
            while (n-- != 0)
            {
                var p : Particle = ppp[n];

                var dx : Number = p.ex - 256;
                var dy : Number = p.ey - 256;

                p.ex = 256 + ((0.9998476951563913) * dx - (0.01745240643728351) * dy);
                p.ey = 256 + ((0.9998476951563913) * dy + (0.01745240643728351) * dx);

                p.fcnt += p.finc;

                var c0 : uint = bmd.getPixel(p.x, p.y);

                var r : uint = (c0 >> 16);
                var g : uint = (c0 >> 8 & 0xFF);
                var b : uint = (c0 & 0xFF);

                if (p.fcnt < 0)
                {
                    r += 0x48;
                    g += 0x46;
                    b += 0x44;

                    p.x += (p.tx - p.x) * 0.033;
                    p.y += (p.ty - p.y) * 0.033;
                }
                else
                {
                    //light = 0x3C2F28;
                    r += 0x48;
                    g += 0x46;
                    b += 0x44;

                    p.x += (p.ex - p.x) * 0.011;
                    p.y += (p.ey - p.y) * 0.011;
                }

                if (r > 0xFF) r = 0xFF;
                if (g > 0xFF) g = 0xFF;
                if (b > 0xFF) b = 0xFF;

                buf[(p.x & 511) + ((p.y & 511) << 9)] = (r << 16 | g << 8 | b);
            }

            bmd.setVector(bmd.rect, buf);

            bmd.unlock();
        }

        private function atomize(src : IBitmapDrawable) : void //
        {
            srcBmd.fillRect(srcBmd.rect, 0x0);
            srcBmd.draw(src);

            var p : Particle;

            var n : uint = NUM_P;
            while (--n != 0) {
                p = ppp[n];

                if (p.finc < 0)//
                {
                    if (p.fcnt < 0) p.fcnt = -p.fmax;
                    p.finc = 1;
                }
            }

            pcnt++;

            var pos : int = (512 * 512) - (512 << 7) - ((fcnt & 1) << 1);
            while (pos > (512 << 7))//
            {
                pos--;
                //pos--;
                //pos--;

                var tx : int = pos & 511;
                var ty : int = pos >> 9;
                if (((ty & 1) == 0) || ((tx & 1) == 0)) continue;

                var tc : uint = srcBmd.getPixel(tx, ty);
                if (tc == 0x0) continue;

                pcnt++;
                //pcnt++;
                // pcnt++;

                p = ppp[pcnt & (NUM_P - 1)];

                if (p.finc > 0)//
                {
                    if (p.fcnt > 0) p.fcnt = p.fmax;
                    p.finc = -1;
                }

                p.tx = tx;
                p.ty = ty;
            }
        }
    }
}

internal class Particle//
{
    // public var next : Particle;
    /* */
    public var fcnt : int;
    public var fmax : int;
    public var finc : int;
    /* */
    public var x : Number;
    public var y : Number;
    public var tx : Number;
    public var ty : Number;
    public var ex : Number;
    public var ey : Number;
}