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

SphericalCoords

move the mouse to rotate.
a timer randomizes the coordinates a bit.
8000 points are computed in 3D,
but projected into 2D as pixels 
using the built in classes in FP10.
/**
 * Copyright George.Profenza ( http://wonderfl.net/user/George.Profenza )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9ug3
 */

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Matrix3D;
    import flash.geom.Point;
    import flash.geom.Utils3D;
    import flash.geom.Vector3D;
    import flash.utils.Timer;

    /**
     * @author george
     */
    final public class FP10 extends Sprite {
        private var matrix : Matrix3D;
        private var uvts : Vector.<Number>;
        private var pVerts : Vector.<Number>;
        private var verts : Vector.<Number>;
        private var canvas : BitmapData;
        private var dx:Number= 0 ;
        private var dy:Number= 0 ;
        private const TWO_PI:Number = Math.PI * 2;
        private const HALF_PI:Number = Math.PI * .5;
        private const sin:Function = Math.sin;
        private const cos:Function = Math.cos;
        private const rad:int = 170;
        private const aInc:Number = HALF_PI * .001;
        private var sInc:int = 18;
        private var tInc:Number = 1;
        private const numPts : int = int(TWO_PI / aInc);
        private var numProj : int;
        private const b : BlurFilter = new BlurFilter(1.4, 1.4, 2);
        private const zero : Point = new Point();
        private var s:Number = 1,sd:int = -1;
        public function FP10() {
            init();
            trace(this);
        }

        private function init() : void {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            matrix = new Matrix3D();
            reset();
            canvas = new BitmapData(512, 512, false, 0x000000);
            addChild(new Bitmap(canvas));
            addEventListener(Event.ENTER_FRAME, update);
            getChildAt(0).cacheAsBitmap = true;
            var t:Timer = new Timer(5000);
            t.addEventListener(TimerEvent.TIMER, reset);
            t.start();
        }

        private function reset(event:TimerEvent = null) : void {
            verts = new Vector.<Number>();
            pVerts = new Vector.<Number>();
            uvts = new Vector.<Number>();
            var s:Number = 0,t:Number = 0;
            sInc = Math.random() * 180;//int(mouseX/sw * 180);
            tInc = .1 + Math.random() * 5;//int(mouseY/sh * 5);
            for (var i : int = 0;i < numPts+1; i++) {
                s+=sInc;
                t+=tInc;
                verts.push(rad * cos(s) * sin(t));
                verts.push(rad * sin(s) * sin(t));
                verts.push(rad * cos(t));
                pVerts.push(0),pVerts.push(0);
                uvts.push(0),uvts.push(0),uvts.push(0);
            }
            numProj  = pVerts.length;
        }
        private function update(evt : Event) : void {
            //rotation+scale update
            evt.stopPropagation();
            dx += (mouseX - dx) * .1;
            dy += (mouseY - dy) * .1;
            s -= .005 * sd;
            b.blurX = b.blurY = s+.25;
            if(s < .25 || s > 1.25) sd *= -1;
            //matrix update+projection
            matrix.identity();
            matrix.appendScale(s,s,s);
            matrix.appendRotation(dy, Vector3D.X_AXIS);
            matrix.appendRotation(dx, Vector3D.Y_AXIS);
            matrix.appendTranslation(256, 256, 0);
            Utils3D.projectVectors(matrix, verts, pVerts, uvts);
            //canvas update+filter
            canvas.lock();
            canvas.fillRect(canvas.rect, 0x000000);
            var i:int = numProj;
            while(i){
                i-=2; 
                canvas.setPixel(pVerts[i], pVerts[i + 1], 0x00009900);
            }
            canvas.applyFilter(canvas, canvas.rect, zero, b);
            canvas.unlock();
        }
    }
}