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: Intersection Momentary

INTERSECTION.MOMENTARY
Original is here.
http://www.complexification.net/gallery/machines/interMomentary/index.php
Intersecting Circles, Instantaneous
J. Tarbell                              + complexification.net
Albuquerque, New Mexico
May, 2004
a REAS collaboration for the            + groupc.net
Whitney Museum of American Art ARTPORT  + artport.whitney.org
Robert Hodgin                           + flight404.com
William Ngan                            + metaphorical.net
Processing 0085 Beta syntax update
j.tarbell   April, 2005
Flash ActionScript 3.0 ported by flashrod
// forked from flashrod's Intersection Momentary
// INTERSECTION.MOMENTARY
//
// Original is here.
// http://www.complexification.net/gallery/machines/interMomentary/index.php
//
// Intersecting Circles, Instantaneous
// J. Tarbell                              + complexification.net
// Albuquerque, New Mexico
// May, 2004
//
// a REAS collaboration for the            + groupc.net
// Whitney Museum of American Art ARTPORT  + artport.whitney.org
// Robert Hodgin                           + flight404.com
// William Ngan                            + metaphorical.net
//
// Processing 0085 Beta syntax update
// j.tarbell   April, 2005
//
// Flash ActionScript 3.0 ported by flashrod
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;

    public class IntersectionMomentary extends Sprite {

        private static const WIDTH:int = 465;
        private static const HEIGHT:int = 465;
        private static const NUM:int = 100;

        private var discs:Array = new Array(NUM);

        public function IntersectionMomentary() {
            var bd:BitmapData = new BitmapData(WIDTH, HEIGHT);
            addChild(new Bitmap(bd));
            var g:JGraphics = new JGraphics(bd);
            for (var i:int = 0; i < NUM; i++) {
                var fx:Number = 0.4* WIDTH *Math.cos((2*Math.PI)*i/WIDTH);
                var fy:Number = 0.4* HEIGHT *Math.sin((2*Math.PI)*i/HEIGHT);
                var x:Number = random(WIDTH/2) + fx;
                var y:Number = random(HEIGHT/2) + fy;
                var r:Number = 5+random(45);
                var bt:int = (random(100) < 50) ? -1 : 1;
                discs[i] = new Disc(i, x, y, bt*fx/1000.0, bt*fy/1000.0, r);
            }
            addEventListener(Event.ENTER_FRAME, function():void { draw(g); });
        }

        private function draw(g:JGraphics):void {
            g.background(0xFF000000);
            for each (var disc:Disc in discs) {
                disc.move(WIDTH, HEIGHT);
                disc.render(g, discs);
                disc.renderPixelRiders(g);
            }
        }
    }
}

import flash.display.BitmapData;
class JGraphics {
    private var bd:BitmapData;
    public function JGraphics(bd:BitmapData) { this.bd = bd; }
    public function background(argb:uint):void {
        bd.fillRect(bd.rect, argb);
    }
    public function get(x:int, y:int):uint {
        return bd.getPixel(x, y);
    }
    public function point(x:int, y:int, gray:int, alpha:Number = 1.0):void {
        var c:int = bd.getPixel(x, y) & 255;
        var b:int = c * (1 - alpha) + gray * alpha;
        bd.setPixel32(x, y, 0xFF000000 | (b << 16) | (b << 8) | (b));
    }
}

class Disc {
    private var id:int;
    private var x:Number;
    private var y:Number;
    private var r:Number;
    private var dr:Number;
    private var vx:Number;
    private var vy:Number;
    private var numr:int;
    private static const MAXR:int =  40;
    private var pxRiders:Array =  new Array(MAXR);

    public function Disc(id:int, x:Number, y:Number, vx:Number, vy:Number, r:Number) {
        this.id = id;
        this.x = x;
        this.y = y;
        this.vx = vx;
        this.vy = vy;
        this.dr = r;
        this.r = 0;
        numr = int(r / 1.62);
        if (numr > MAXR) {
            numr = MAXR;
        }
        for (var n:int = 0; n < MAXR; n++) {
            pxRiders[n] =  new PixelRider();
        }
    }

    public function render(g:JGraphics, discs:Array):void {
        for (var n:int = id+1; n < discs.length; n++) {
            var disc:Disc = discs[n];
            var dx:Number = disc.x-x;
            var dy:Number = disc.y-y;
            var d:Number = Math.sqrt(dx*dx+dy*dy);
            if (d<(disc.r+r)) {
                if (d>Math.abs(disc.r-r)) {
                    var a:Number = (r*r - disc.r*disc.r + d*d) / (2*d);
                    var p2x:Number = x + a*(disc.x - x)/d;
                    var p2y:Number = y + a*(disc.y - y)/d;
                    var h:Number = Math.sqrt(r*r - a*a);
                    var p3ax:Number = p2x + h*(disc.y - y)/d;
                    var p3ay:Number = p2y - h*(disc.x - x)/d;
                    var p3bx:Number = p2x - h*(disc.y - y)/d;
                    var p3by:Number = p2y + h*(disc.x - x)/d;
                    g.point(p3ax, p3ay, 255);
                    g.point(p3bx, p3by, 255);
                }
            }
        }
    }

    public function move(width:int, height:int):void {
        x += vx;
        y += vy;
        if (x+r < 0) {
            x += width + r + r;
        }
        if (x-r > width) {
            x -= width + r + r;
        }
        if (y+r < 0) {
            y += height + r + r;
        }
        if (y-r > height) {
            y -= height + r + r;
        }
        if (r < dr) {
            r += 0.1;
        }
    }

    public function renderPixelRiders(g:JGraphics):void {
        for each (var px:PixelRider in pxRiders) {
            px.move(g, x, y, r);
        }
    }
}

class PixelRider {
    private var t:Number;
    private var vt:Number = 0.0;
    private var mycharge:int;
    public function PixelRider() {
        t = random((2*Math.PI));
    }
    public function move(g:JGraphics, x:Number, y:Number, r:Number):void {
        // add velocity to theta
        t = (t + vt + Math.PI) % (2 * Math.PI) - Math.PI;
        vt += random(-0.001, 0.001);
        // apply friction brakes
        if (Math.abs(vt) > 0.02) {
            vt *= 0.9;
        }
        // draw
        var px:Number = x + r * Math.cos(t);
        var py:Number = y + r * Math.sin(t);
        var c:uint = g.get(int(px), int(py));
        if ((c & 255) > 48) {
            glowpoint(g, px, py);
            mycharge = 164;
        } else {
            g.point(px, py, mycharge);
            mycharge *= 0.98;
        }
    }

    private function glowpoint(g:JGraphics, px:Number, py:Number):void {
        for (var i:int = -2; i < 3; i++) {
            for (var j:int = -2; j < 3; j++) {
                var a:Number = 0.8 - i * i * 0.1 - j * j * 0.1;
                g.point(px + i, py + j, 255, a);
            }
        }
    }
}

function random(...args):Number {
    switch (args.length) {
    case 2:
        var min:Number = args[0];
        var max:Number = args[1];
        return Math.random() * (max - min) - min;
    case 1:
        return Math.random() * Number(args[0]);
    }
    return Math.random();
}