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

forked from: Midpoint Donut

Get Adobe Flash player
by hemingway 10 Sep 2012
/**
 * Copyright hemingway ( http://wonderfl.net/user/hemingway )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kXtY
 */

// forked from flashmafia's Midpoint Donut
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 = '465', height = '465', backgroundColor = '0x000000', frameRate = '32')]
    public class Main extends Sprite {
        private const NUM_PARTICLES : int = 555555;
        private const SIZE_X : int = 512;
        private const SIZE_Y : int = 512;
        private const RADIUS : Number = 2222;
        private const THICKNESS : Number = RADIUS / 3;
        private const DEGREE : Number = 8;
        private const RADIAN : Number = DEGREE * Math.PI / 180;
        private const ECOS : Number = Math.cos(RADIAN * 1.1);
        private const ESIN : Number = Math.sin(RADIAN);
        /* */
        private var _p : Particle;
        private var _bitmapData : BitmapData;
        private var _buffer : Vector.<uint>;

        public function Main() : void {
            mouseEnabled = mouseChildren = tabEnabled = tabChildren = false;
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.LOW;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.fullScreenSourceRect = new Rectangle(0, 0, SIZE_X, SIZE_Y);

            var a : Number = 0;
            var p : Particle = _p = new Particle();
            var n : int = NUM_PARTICLES;
            while (--n != 0) {
                a += Math.PI * 2 / NUM_PARTICLES;
                p.x = p.ex = (SIZE_X >> 1) + (RADIUS + THICKNESS * Math.sin(a * 1111)) * Math.cos(a);
                p.y = p.ey = (SIZE_Y >> 1) + (RADIUS + THICKNESS * Math.cos(a * 1111)) * Math.sin(a);
                p = p.next = new Particle();
            }

            addChild(new Bitmap(_bitmapData = new BitmapData(SIZE_X, SIZE_Y, false, 0x0)));
            _buffer = new Vector.<uint>(SIZE_X * SIZE_Y, true);

            addEventListener(Event.ENTER_FRAME, animate);
        }

        private function animate(e : Event) : void {
            const sx : int = SIZE_X;
            const cx : int = SIZE_X >> 1;
            const cy : int = SIZE_Y >> 1;
            const ecos : Number = ECOS;
            const esin : Number = ESIN;

            var n : uint = _buffer.length;
            while (--n != 0) _buffer[n] = 0x110011;

            var p : Particle = _p;
            while (p != null) {
                var dx : Number = p.ex - cx;
                var dy : Number = p.ey - cy;
                p.ex = cx + (ecos * dx - esin * dy);
                p.ey = cy + (ecos * dy + esin * dx);
                
                            
                
                p.x += (p.ex - p.x) >> 6;
                p.y += (p.ey - p.y) >> 6;

                n = (p.y & 511) * sx + (p.x & 511);

                var c : uint = _buffer[n];
                var r : uint = (c >> 16) + 16;
                var g : uint = (c >> 8 & 0xFF) + 8;
                var b : uint = (c & 0xFF) + 12;
                r = (r > 255) ? 255 : r;
                g = (g > 255) ? 255 : g;
                b = (b > 255) ? 255 : b;

                r = (r > 255) ? 255 : r;
                g = (g > 255) ? 255 : g;
                b = (b > 255) ? 255 : b;

                _buffer[n] = (r << 16) | (g << 8) | (b >> 1);

                p = p.next;
            }

            _bitmapData.setVector(_bitmapData.rect, _buffer);
        }
    }
}
internal final class Particle {
    public var x : int;
    public var y : int;
    public var ex : int;
    public var ey : int;
    public var next : Particle;
}