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

CustomLine3D

Get Adobe Flash player
by bradsedito 27 Nov 2011



package 
{
    import flash.display.*;
    import flash.events.*;
    
    [SWF(width="480",height="360",backgroundColor=0xffffff)]
 
    public class FlashTest extends Sprite 
    {
        public  var SW:Number = stage.stageWidth;
        public  var SH:Number = stage.stageHeight;
        
        public function FlashTest() 
        {
            var sp1:Sprite=new Sprite();
            var sp2:Sprite=new Sprite();
            sp1.x = SW/2;
            sp1.y = SH/2;
            //sp1.z = 400;
            addChild(sp1);
            
            sp2.x = SW/2;
            sp2.y = SH/2;
            //sp2.z = 400;
            addChild(sp2);
            
            var g1:Graphics3D = new Graphics3D(sp1);
            g1.lineStyle(10,0xFF6600,1);      // (lineSize,lineColor,lineAlpha)
            g1.moveTo(240,-180,8191);         //  moveTo( x,y,z        );
            g1.lineTo(-150,100,0);            // curveTo( x,y,z,x,y,z  );
        
            var g2:Graphics3D = new Graphics3D(sp1);
            g2.lineStyle(10,0x0066FF,1);      // (lineSize,lineColor,lineAlpha)
            g2.moveTo(-200,-300,8191);        //  moveTo( x,y,z        );
            g2.curveTo(-900,-10,0,200,180,0); // curveTo( x,y,z,x,y,z  );
        }
        
    }
}



import flash.display.Sprite;
import flash.display.Graphics; 
class Graphics3D
{
    private var g:Graphics;
    private var thickness:Number=0;
    private var lineColor:uint=0;
    private var lineAlpha:Number=1.0;
    private var startX:Number=0;
    private var startY:Number=0;
    private var startZ:Number=0;
    public var vs:Number=-200;
       
    public function Graphics3D(target:Sprite,vs:Number=-100)
    {
            this.g=target.graphics;
            this.vs=vs;
    }
    
    public function clear():void
    {
        g.clear();
    }
        public function lineStyle(thickness:Number,color:uint=0,alpha:Number=1.0):void{
            this.thickness=thickness;
            this.lineColor=color;
            this.lineAlpha=alpha;
        }
        public function moveTo(x:Number,y:Number,z:Number):void{
            this.startX=x;
            this.startY=y;
            this.startZ=z;
        }
        public function lineTo(x:Number,y:Number,z:Number):void{
            //g.lineStyle(undefined);
            var p:Number=-vs/(-vs+this.startZ);
            g.beginFill(lineColor,lineAlpha);
            var r1:Number=this.thickness*p/2;
            var startX:Number=this.startX*p;
            var startY:Number=this.startY*p;
            g.drawCircle(startX,startY,r1);
            g.endFill();
            g.beginFill(lineColor,lineAlpha);
            p=-vs/(-vs+z);
            var r2:Number=thickness*p/2;
            var endX:Number=x*p;
            var endY:Number=y*p;
            g.drawCircle(endX,endY,r2);
            g.endFill();
            g.beginFill(lineColor,lineAlpha);
            var s:Number=endX-startX;
            var t:Number=endY-startY;
            var u:Number=Math.asin((r1-r2)/Math.sqrt(s*s+t*t));
            var v:Number=Math.atan2(s,t);
            var a1:Number=u-v;
            var a2:Number=Math.PI-u-v;
            //g.lineStyle(0,0xff0000);
            g.moveTo(r1*Math.cos(a1)+startX,r1*Math.sin(a1)+startY);
            g.lineTo(r1*Math.cos(a2)+startX,r1*Math.sin(a2)+startY);
            g.lineTo(r2*Math.cos(a2)+endX,r2*Math.sin(a2)+endY);
            g.lineTo(r2*Math.cos(a1)+endX,r2*Math.sin(a1)+endY);
            g.endFill();
            moveTo(x,y,z);
        }
        public function curveTo(controlX:Number,controlY:Number,controlZ:Number,anchorX:Number,anchorY:Number,anchorZ:Number):void{
            var startX:Number=this.startX;
            var startY:Number=this.startY;
            var startZ:Number=this.startZ;
            for(var i:Number=0;i<=1;i+=0.01){
                var j:Number=1-i;
                var tX:Number=j*(j*startX+i*controlX)+i*(j*controlX+i*anchorX);
                var tY:Number=j*(j*startY+i*controlY)+i*(j*controlY+i*anchorY);
                var tZ:Number=j*(j*startZ+i*controlZ)+i*(j*controlZ+i*anchorZ);
                lineTo(tX,tY,tZ);
            }
        }
    }