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

Tetrominos

Get Adobe Flash player
by k__ 30 May 2009
    Embed
/**
 * Copyright k__ ( http://wonderfl.net/user/k__ )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kKsq
 */


package {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import org.papervision3d.cameras.*;
	import org.papervision3d.materials.shadematerials.*;
	import org.papervision3d.materials.special.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.materials.utils.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.render.*;
	import org.papervision3d.scenes.*;
	import org.papervision3d.view.*;
	import org.papervision3d.lights.*;
	
	public class Main extends Sprite {
		private var scene:Scene3D;
		private var camera:Camera3D;
		private var viewport:Viewport3D;
		private var renderer:BasicRenderEngine;
		private var objects:Array = [];
		private var material:	PhongMaterial	;
		private var light:PointLight3D;
		
		private var blockDef:Array = [
						[[0,0],[1,0],[1,1],[0,1]],
						[[1,0],[2,0],[3,0],[4,0]],
						[[0,0],[0,1],[0,2],[1,1]],
						[[0,0],[1,0],[1,1],[2,1]],
						[[0,1],[1,1],[1,0],[2,0]],
						[[0,1],[1,1],[1,0],[2,0]],
						[[0,0],[1,0],[2,0],[0,1]],
						[[0,0],[1,0],[2,0],[2,1]]
						]

		public function Main() {
			//bg
			graphics.beginFill(0x000000);
			graphics.drawRect(0,0,500,500);
			scene = new Scene3D();
			//camera
			camera = new Camera3D();
			camera.x = camera.y = 0;
			camera.z = -1000;
			camera.focus = 100;
			camera.zoom = 10;
			//vieport
			viewport = new Viewport3D(500,500);
			addChild(viewport);

			//renderer
			renderer = new BasicRenderEngine();

			//light
			light = new PointLight3D();
			light.x = 100;
			light.y = 100;
			light.z = -100;
			scene.addChild(light);

			// create materials
			
			material = new PhongMaterial	(light, 0xffffff, 0x888888,4);
			
			//create objects
			var cnt:uint = 0;
			var mList:MaterialsList;
			var object:DisplayObject3D, cube:DisplayObject3D;
			for (var j:uint = 0; j <= 300; j += 100) {
				for (var i:uint = 0; i <= 300; i += 100) {
					cnt = (cnt + 1) % blockDef.length;
					mList= new MaterialsList();
					mList.addMaterial(material ,"all");
					object = new DisplayObject3D;
					for (var k:uint = 0; k < blockDef[cnt].length; k ++) {
						cube = new Cube(mList,20,20,20);
						cube.x = blockDef[cnt][k][0] * 20;
						cube.y = blockDef[cnt][k][1] * 20;
						object.addChild(cube);
					}
					
					object.x=i - 150;
					object.y=j - 150;
					objects.push(object);
					scene.addChild(object);
				}
			}
			stage.addEventListener(Event.ENTER_FRAME, drawPapervision3d);
		}

		private function drawPapervision3d(e:Event):void {
			for (var i:uint = 0; i < objects.length; i ++) {
				objects[i].rotationX+=1;
				objects[i].rotationY+=1;
				objects[i].rotationZ+=1;
			}
			renderer.renderScene(scene, camera, viewport);
		}

	}
}