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

Cube 3D

Get Adobe Flash player
by Yukulele 11 Mar 2009
package 
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Matrix3D;
	import flash.geom.Point;
	import flash.geom.Vector3D;
	import flash.utils.Timer;
    public class Main extends Sprite 
    {
		private var carres:Vector.<Shape> = new Vector.<Shape>;
		private static const VITESSE:Number = 4;
		private var cercle:Shape = new Shape();
        public function Main():void 
        {
			transform.matrix3D = new Matrix3D();
			var mat:Matrix3D = new Matrix3D();
			var timer :Timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
				mat = new Matrix3D();
				mat.appendRotation((Math.random()-.5)*VITESSE, Vector3D.X_AXIS);
				mat.appendRotation((Math.random()-.5)*VITESSE, Vector3D.Y_AXIS);
				mat.appendRotation((Math.random() - .5) * VITESSE, Vector3D.Z_AXIS);
			});
			timer.start();
			stage.addEventListener(MouseEvent.MOUSE_MOVE,zoomer);
			stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void {	
				for (var ind:int = 0; ind < carres.length; ind++)
				{ 
					carres[ind].transform.matrix3D.append(mat);
				}
				ReorderChildren();
			});
			cercle.graphics.beginFill(0xff0000);
			cercle.graphics.drawCircle( 0,0, 10);
			carres.push(new Carre(0,0,1,Vector3D.Z_AXIS));
			carres.push(new Carre(0,0,-1,Vector3D.Z_AXIS));
			carres.push(new Carre(1, 0, 0, Vector3D.Y_AXIS));
			carres.push(cercle);
			carres.push(new Carre(-1,0,0,Vector3D.Y_AXIS));
			carres.push(new Carre(0,1,0,Vector3D.X_AXIS));
			carres.push(new Carre(0, -1, 0,Vector3D.X_AXIS));
			for (var i:int = 0; i < carres.length; i++)
			{				
				addChild(carres[i]);
			}
			x = stage.stageWidth / 2;
			y = stage.stageHeight / 2;
        }
		public function ReorderChildren():void
		{
			carres.sort(tri);
			for (var ind:int = 0; ind < carres.length; ind++)
			{ 
				this.setChildIndex(carres[ind],ind);
			}
		}
		private function tri(a:Shape,b:Shape):Number
		{
			return (b.z - a.z);
		}
		private function zoomer(e:MouseEvent):void
		{
			transform.perspectiveProjection.fieldOfView =Math.min(179,Math.max(1,e.stageX*180/stage.stageWidth));
		}
    } 
}

import flash.display.Shape;
import flash.geom.Matrix3D;
import flash.geom.PerspectiveProjection;
import flash.geom.Vector3D;

class Carre extends Shape
{
	private static const TAILLE:Number = 150;
	private static const DISTANCE:Number = 0;
	public var zz:Number;
	public function Carre(x:Number=0,y:Number=0,z:Number=0,axe:Vector3D=Vector3D.X_AXIS) 
	{
		graphics.beginFill(0xffffff*Math.random());
		graphics.lineStyle(1, 0);
		graphics.drawRect( -TAILLE / 2, -TAILLE / 2, TAILLE, TAILLE);
		
		var mat:Matrix3D = new Matrix3D();
		mat.appendRotation( 90, axe);
		this.transform.matrix3D = mat;
		this.x = x * (TAILLE / 2 + DISTANCE);
		this.y = y * (TAILLE / 2 + DISTANCE);
		this.z = z * (TAILLE / 2 + DISTANCE);
		alpha = .8;
	}
}