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

flash on 2009-3-17

Get Adobe Flash player
by grLynx 19 Oct 2010
package {
	import alternativ5.engine3d.core.Camera3D;
	import alternativ5.engine3d.core.Object3D;
	import alternativ5.engine3d.core.Scene3D;
	import alternativ5.engine3d.display.View;
	import alternativ5.engine3d.materials.WireMaterial;
	import alternativ5.engine3d.primitives.Box;
	import alternativ5.utils.FPS;
        import alternativ5.types.Texture;
        import alternativ5.engine3d.materials.TextureMaterial;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
        import flash.display.BitmapData;
        
        import flash.geom.Point;

	[SWF(backgroundColor="#000000", frameRate="60")]

	public class HelloAlternativa3D extends Sprite	{
		
		private var scene:Scene3D;
		private var view:View;
		private var camera:Camera3D;
		private var box:Box;
                private var bmp:BitmapData;
                private var offsets:Array;
                private var deltas:Array;
                private var seed:Number = Math.random()*100;
		
		public function HelloAlternativa3D() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		public function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);

			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			// Создание сцены
			scene = new Scene3D();
			scene.root = new Object3D();
			box = new Box(100, 100, 100, 3, 3, 3);
                        bmp = new BitmapData(100, 100, false, 0);
                        offsets = [];
                        deltas = [];
                        for (var i:int = 0; i < 3; i++) {
                            offsets[i] = new Point(0, 0);
                            deltas[i] = new Point((1 - 2*Math.random())*5, (1 - 2*Math.random())*5);
                        }
                        
			box.cloneMaterialToAllSurfaces(new TextureMaterial(new Texture(bmp)));
			scene.root.addChild(box);
			
			// Добавление камеры и области вывода
			camera = new Camera3D();
			camera.x = 0;
			camera.y = -150;
			camera.z = 100;
                        camera.rotationX = -0.7*Math.PI;
			scene.root.addChild(camera);
			
			view = new View();
			addChild(view);
			view.camera = camera;

			// Запуск счётчика кадров
			FPS.init(stage);

			stage.addEventListener(Event.RESIZE, onResize);
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			onResize(null);
		}
		
		private function onResize(e:Event):void {
			view.width = stage.stageWidth;
			view.height = stage.stageHeight;
		}
		
		private function onEnterFrame(e:Event):void {
			// Расчёт сцены
                        box.rotationX += 0.01;
                        box.rotationY += 0.02;
                        box.rotationZ += 0.03;


                        for (var i:int = 0; i < 3; i++) {
                            offsets[i].x += deltas[i].x;
                            offsets[i].y += deltas[i].y;
                        }
                        bmp.fillRect(bmp.rect, 0);
                        bmp.perlinNoise(50, 50, 3, seed, true, true, 2, false, offsets);

			scene.calculate();
		}
	}
}