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

Box(Test)

ひとまず立方体。
慣れるとだいぶ楽にできる

やっぱりQuaternion使わないときれいな回転はできないな・・・
Get Adobe Flash player
by phi16 03 Apr 2011
/**
 * Copyright phi16 ( http://wonderfl.net/user/phi16 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/i2UW
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    public class Box3D extends Sprite {
        public var spr:Sprite=new Sprite();
        private var rad:Number=0;
        private var dirx:Number=0,diry:Number=0;
        public function Box3D() {
            spr.x=spr.y=235;
            this.addChild(spr);
            this.addEventListener(Event.ENTER_FRAME,this.Draw);
        }
        private function Draw(e:Event):void{
            spr.graphics.clear();
            var vertexs:Array=new Array(
                -1,-1,-1,
                -1,1,-1,
                -1,1,1,
                -1,-1,1,
                
                1,-1,-1,
                1,1,-1,
                1,1,1,
                1,-1,1);
            var colr:int,colg:int,colb:int;
            colr=(Math.sin(rad*Math.PI/180)+1)*255/2;
            colg=(Math.sin((rad+120)*Math.PI/180)+1)*255/2;
            colb=(Math.sin((rad-120)*Math.PI/180)+1)*255/2;
            for(var i:int=0;i<8;i++){
                var x:Number,y:Number,z:Number,x2:Number,y2:Number,z2:Number;
                x=vertexs[i*3];
                y=vertexs[i*3+1];
                z=vertexs[i*3+2];
                x2=x*Math.cos(diry*Math.PI/180)+z*Math.sin(diry*Math.PI/180);
                y2=y;
                z2=-x*Math.sin(diry*Math.PI/180)+z*Math.cos(diry*Math.PI/180);
                x=x2,y=y2,z=z2;
                x2=x;
                y2=y*Math.cos(dirx*Math.PI/180)-z*Math.sin(dirx*Math.PI/180);
                z2=y*Math.sin(dirx*Math.PI/180)+z*Math.cos(dirx*Math.PI/180);
                vertexs[i*3]=x2*4/(4+z2);
                vertexs[i*3+1]=y2*4/(4+z2);
                vertexs[i*3+2]=z2;
            }
            for(i=0;i<4;i++){
                spr.graphics.lineStyle(5,colr*256*256+colg*256+colb);
                spr.graphics.moveTo(vertexs[i*3]*100,vertexs[i*3+1]*100);
                spr.graphics.lineTo(vertexs[(i+1)%4*3]*100,vertexs[(i+1)%4*3+1]*100);
                spr.graphics.lineStyle(5,colr*256*256+colg*256+colb);
                spr.graphics.moveTo(vertexs[(i+4)*3]*100,vertexs[(i+4)*3+1]*100);
                spr.graphics.lineTo(vertexs[((i+1)%4+4)*3]*100,vertexs[((i+1)%4+4)*3+1]*100);
                spr.graphics.lineStyle(5,colr*256*256+colg*256+colb);
                spr.graphics.moveTo(vertexs[i*3]*100,vertexs[i*3+1]*100);
                spr.graphics.lineTo(vertexs[(i+4)*3]*100,vertexs[(i+4)*3+1]*100);
            }
            
            rad+=2;
            diry+=2;
            dirx+=2;
        }
    }
}