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

Shenron

@author seyself
Get Adobe Flash player
by seyself 26 Dec 2008
/**
 * @author seyself
 */
package  
{
import flash.display.Graphics;
import flash.display.GraphicsPathCommand;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix3D;
import flash.geom.Point;
import flash.geom.Utils3D;
import flash.geom.Vector3D;

[SWF(width=465, height=465, backgroundColor=0x121212, frameRate=60)]
public class Arrow extends Sprite
{
    private var matrix:Matrix3D = new Matrix3D();
    private var rotate:Matrix3D = new Matrix3D();
    private var translate:Matrix3D = new Matrix3D();
    private var view:Vector3D = new Vector3D();
    private var hin:Vector.<Number> = new Vector.<Number>();
    private var hout:Vector.<Number> = new Vector.<Number>();
    private var vin:Vector.<Number> = new Vector.<Number>();
    private var vout:Vector.<Number> = new Vector.<Number>();
    
    private var px:Number = 0;
    private var py:Number = 0;
    private var pz:Number = 0;
    
    public function Arrow() 
    {
        this.x = stage.stageWidth / 2;
        this.y = stage.stageHeight / 2;
        
        var vz:Number = 0;
        
        hin.push(  0,  0, vz);
        hin.push( 30, 50, vz);
        hin.push(  0, 30, vz);
        hin.push(-30, 50, vz);
        
        hin.push(-10, 30, vz);
        hin.push( 10, 30, vz);
        hin.push( 10, 50, vz);
        hin.push(-10, 50, vz);
        
        vin.push( 10, 60, vz);
        vin.push(-10, 60, vz);
        vin.push(-10, 50, vz);
        vin.push( 10, 50, vz);
        
        hout = hin.concat();
        vout = hout.concat(vin);
        
        px = hout[0];
        py = hout[1];
        pz = hout[2];
        
        addEventListener("enterFrame", loop);
        
    }
    
    private function loop(event:Event):void 
    {
        move();
        draw();
    }
    
    private var base:Vector3D = new Vector3D(50, 80, 120);
    private var ax:Number = 0;
    private var ay:Number = 0;
    private var az:Number = 0;
    
    private function move():void
    {
        var rx:Number = mouseY / 50;
        var ry:Number = mouseX / 50;
        var rz:Number = (rx + ry) * 0.75;
        
        rotate.appendRotation(rx, Vector3D.X_AXIS);
        rotate.appendRotation(ry, Vector3D.Y_AXIS);
        rotate.appendRotation(rz, Vector3D.Z_AXIS);
        rotate.transformVectors(hin, hout);
        
        var d:Number = 1.2;
        translate.appendTranslation((hout[0]-hout[6]) * d, (hout[1]-hout[7]) * d, (hout[2]-hout[8]) * d);
        translate.transformVectors(hout, hout);
        
        
        var n:uint = vin.length;
        var t1:Vector.<Number> = vin.slice(n - 6, n - 3);
        var t2:Vector.<Number> = vin.slice(n - 3, n - 0);
        vin = vin.concat(t2);
        vin = vin.concat(t1);
        vin = vin.concat(hout.slice(21, 24));
        vin = vin.concat(hout.slice(18, 21));
        
        if (vin.length > 3 * 4 * 300)
        {
            vin.splice(0, 12);
        }
        
        vout = hout.concat(vin);
        
        view.x -= (view.x + (hout[0] - view.x) * 0.0125) * 0.5;
        view.y -= (view.y + (hout[1] - view.y) * 0.0125) * 0.5;
        view.z -= (view.z + (hout[2] - view.z) * 0.0125) * 0.5;
        
        ax = Math.cos(view.x * 0.001) * 400;
        ay = Math.sin(view.y * 0.001) * 400;
        az = Math.cos(view.z * 0.01) * 200;
        
        matrix = new Matrix3D();
        matrix.append(rotate);
        matrix.append(translate);
        matrix.invert();
        matrix.appendTranslation(view.x*0.1 + ax, view.y*0.1 + ay, view.z*0.01);
        matrix.appendRotation(view.x, Vector3D.X_AXIS, base);
        matrix.appendRotation(view.y, Vector3D.Y_AXIS, base);
        matrix.appendRotation(view.z, Vector3D.Z_AXIS, base);
        matrix.appendTranslation(0, 0, 500 + az);
        matrix.transformVectors(vout, vout);
        
        px = hout[0];
        py = hout[1];
        pz = hout[2];
        
    }
    
    private function draw():void
    {
        graphics.clear();
        
        var f:uint = 280;
        var n:uint = vout.length;
        for (var i:uint = 0; i < n; i+=12) 
        {
            var a:Number = i / n * 2.5;
            if (a > 1) a = 1;
            if (i < 24) a = 1;
            
            if (vout[i+2 + 3 * 0] < -f 
                || vout[i+2 + 3 * 1] < -f
                || vout[i+2 + 3 * 2] < -f 
                || vout[i+2 + 3 * 3] < -f)
            {
                continue;
            }
            
            graphics.beginFill(0xFFFFFF, a);
            
            _drawPath(graphics.moveTo, vout[i+9], vout[i + 10], vout[i + 11], f);
            
            var m:uint = i + 12;
            for (var j:uint = i; j < m; j+=3) 
            {
                _drawPath(graphics.lineTo, vout[j], vout[j + 1], vout[j + 2], f);
            }
            graphics.endFill();
        }
    }
    
    private function _drawPath(command:Function, 
        x:Number, y:Number, z:Number, f:Number=250):void
    {
        //if (z < -f) return;
        var s:Number = f / ( f + z );
        var nx:Number = x * s;
        var ny:Number = y * s;
        command(nx, ny);
    }
}

}