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

[PV3D]RefrectionView

Get Adobe Flash player
by arfyasu 16 Feb 2009
    Embed
package 
{
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import org.papervision3d.core.effects.view.ReflectionView;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.objects.primitives.Plane;
    import caurina.transitions.Tweener;

    [SWF(backgroundColor = "#000000")]
    public class Main extends ReflectionView
    {
		private const SPEED:Number = 5;
        private var cubes:Array = [];
        private var cubeSpeed:Array = [];
		
        public function Main():void {
            //リフレクションを置く場所
            surfaceHeight = 0;
            //ぼかし反映
            var blur:Number = 4;
            viewportReflection.filters = [new BlurFilter(blur, blur, 1)];
            //鏡面反射用平面(分かりやすいようにワイヤーフレーム表示)
            var size:Number = 1000;
            var rPlane:Plane = new Plane(new WireframeMaterial(0xffffff), size, size, 10, 10);
            rPlane.rotationX = 90;
            scene.addChild(rPlane);
            //キューブ生成
            createCube();
            //イベント定義
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        // キューブ生成
        private function createCube():void {
            var size:Number = 150;
            var length:int = 3;
            var space:Number = 200;
            // 斜めに等間隔でキューブを配置
            for (var i:int = 0; i < length; i++) {
                var cube:Cube = new Cube(getRandomColorMaterialList(), size, size, size);
                cube.x = (i - 1) * space;
                cube.y = Math.random() * space + 100;
                cube.z = (i - 1) * space;
                scene.addChild(cube);
				cubes.push(cube);
				cubeSpeed.push(SPEED); 
				if (i % 2 == 0) { cubeSpeed[i] *= -1; }
            }
        }
        
        //マテリアルカラーをランダム作成        
        private function getRandomColorMaterialList():MaterialsList{
            return new MaterialsList( {
                front  : new ColorMaterial(Math.random() * 0xffffff),
                back   : new ColorMaterial(Math.random() * 0xffffff),
                left   : new ColorMaterial(Math.random() * 0xffffff),
                right  : new ColorMaterial(Math.random() * 0xffffff),
                top    : new ColorMaterial(Math.random() * 0xffffff),
                bottom : new ColorMaterial(Math.random() * 0xffffff)
            });
        }
        
        //レンダリング
        private function onEnterFrame(e:Event):void {
			moveCube();
            var pitch : Number = (-mouseY * 0.15);
            if (pitch >= 0)
                pitch = -0.1;
            camera.orbit(pitch, mouseX * 0.5);
            //1回のみレンダリング
            singleRender();
        }
		
		private function moveCube():void {
			for (var i:int = 0; i < cubes.length; i++) {
				var cube:Cube = cubes[i];
				cube.y += cubeSpeed[i];
				if (cube.y < 100 || cube.y > 500) {
					cubeSpeed[i] *= -1;
				}
            }
		}

    }    
}