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

Bezier3D in pure AS3

I think most of this was originally from quasimando but i'm not sure, heres my take on it.
Get Adobe Flash player
by bradsedito 01 Nov 2011
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6f7p
 */

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
   
    [SWF(backgroundColor=0x333333, frameRate=60)]; 
    //[SWF(backgroundColor=0x333333, width=800, height=600)]; 
     
    public class Bezier3D extends Sprite 
    {
        private var verts:Vector.<Number>  = new Vector.<Number>();
        private var tVerts:Vector.<Number> = new Vector.<Number>();
        private var pVerts:Vector.<Number> = new Vector.<Number>();
        private var uvts:Vector.<Number> = new Vector.<Number>();
        private var igraph:Vector.<IGraphicsData> = new Vector.<IGraphicsData>(); 
        private var tVect:Vector3D = new Vector3D();
        private var m:Matrix3D = new Matrix3D();
        
        public function Bezier3D() 
        {
            x = stage.stageWidth / 2;
            y = stage.stageHeight / 2;
            
            var verts:Vector.<Number>  = new Vector.<Number>();
            var tVerts:Vector.<Number> = new Vector.<Number>();
            var pVerts:Vector.<Number> = new Vector.<Number>();
            var uvts:Vector.<Number> = new Vector.<Number>();
            var igraph:Vector.<IGraphicsData> = new Vector.<IGraphicsData>();
            var tVect:Vector3D = new Vector3D();
            var m:Matrix3D = new Matrix3D();
            var col:int = [0xFFFFFF, 0x000000, 0xFFCC00, 0xFF0000][int(Math.random() * 4)];
           
            addEventListener(Event.ENTER_FRAME, onLoop);

            for (var i:int = 0; i<200; i++)
            {
                for (var j:int = 0; j<3; j++)
                {
                    tVect.x = Math.random() * 0.15;
                    m.identity();
                    m.appendRotation(Math.random()*360, Vector3D.X_AXIS);
                    m.appendRotation(Math.random()*360, Vector3D.Y_AXIS);
                    m.appendRotation(Math.random()*360, Vector3D.Z_AXIS);
                    tVect = m.transformVector(tVect);
                    verts.push(tVect.x, tVect.y, tVect.z);
                }
   
                    var stroke:GraphicsStroke = new GraphicsStroke();
                    stroke.thickness = 2+(Math.random()*Math.random())*8;
                    stroke.fill = new GraphicsSolidFill( 0x131413,1 );
                    //stroke.fill = new GraphicsGradientFill(GradientType.RADIAL, [0xFFFFFF,0x444444], [1, 1], [30, 255], mg);
                    //stroke.fill = new GraphicsGradientFill(GradientType.RADIAL, [0xFFFFFF,0x444444], [1, 1], [30, 255], mg);
                
                    var mg:Matrix = new Matrix();
                    mg.createGradientBox(350+Math.random()*20-10, 350+Math.random()*20-10, 0, -270+i/2,-240+i/2);
                 
                    var bez:GraphicsPath = new GraphicsPath();
                    bez.commands = Vector.<int>([1, 3]);
                    igraph.push(stroke);
                    igraph.push(bez);
                }
                 
                var perspective:PerspectiveProjection = new PerspectiveProjection();
                perspective.fieldOfView = 65;
                
                var trans:Matrix3D = new Matrix3D();
                var proj:Matrix3D = perspective.toMatrix3D();
                var dx:Number = 0, dy:Number = 0;
                 

                function onLoop(evt:Event):void 
                {
                    dx += (mouseX - dx) / 4;
                    dy += (mouseY - dy) / 4;
                       
                    trans.identity();
                    trans.appendRotation(dy, Vector3D.X_AXIS);
                    trans.appendRotation(dx, Vector3D.Y_AXIS);
                    trans.appendTranslation(0,0,0.5);
                    trans.transformVectors(verts, tVerts);
                    Utils3D.projectVectors(proj, tVerts, pVerts, uvts);
                   
                    var inc:int = 0;
                    for (var i:int = 1; i<igraph.length; i+=2)
                    {
                        GraphicsPath(igraph[i]).data = pVerts.slice(inc, inc + 10);
                        inc += 10;
                    }
                     
                    graphics.clear();
                    graphics.drawGraphicsData(igraph);
                }   
        }
        
        
        
    }
}