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: Bezier3D in pure AS3

[SWF(backgroundColor=0x333333, width=800, height=600)];
/**
 * Copyright Mier.Soleil ( http://wonderfl.net/user/Mier.Soleil )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xbTB
 */

// forked from bradsedito's Bezier3D in pure AS3
package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
   
    [SWF(width = "1280", height = "720", frameRate = "60", backgroundColor = 0x000000)]
    //[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 = [0x000000, 0x000000, 0x000000, 0x000000][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.25;
                    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( 0xff0000,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);
                }   
        }
        
        
        
    }
}