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

Away3D [cube]

////////////////////////////////////////////////////////////////////////////////
// Away3D [cube]
//
// [Away3D] 立方体 (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1767
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 17 Sep 2012
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4FoY
 */

////////////////////////////////////////////////////////////////////////////////
// Away3D [cube]
//
// [Away3D] 立方体 (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1767
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.system.System;
    import flash.events.Event;
    import flash.geom.Vector3D;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import away3d.Away3D;
    import away3d.containers.View3D;
    import away3d.containers.Scene3D;
    import away3d.cameras.Camera3D;
    import away3d.lights.PointLight;
    import away3d.entities.Mesh;
    import away3d.primitives.CubeGeometry;
    import away3d.materials.TextureMaterial;
    import away3d.textures.BitmapTexture;
    import away3d.materials.lightpickers.StaticLightPicker;
    import away3d.debug.AwayStats;

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

    public class Main extends Sprite {
        private var view:View3D;
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var light:PointLight;
        private static var max:uint = 200;
        private static var radius:uint = 500;
        private var angle:Number = 90;
        private var degree:Number = 0;
        private static var depression:uint = 30;
        private static var radian:Number = Math.PI/180;
        private static var center:Vector3D = new Vector3D();
        private var stats:AwayStats;
        //private var source:BitmapData = new BitmapData(465, 465, false, 0x000000);

        public function Main() {
            Wonderfl.disable_capture();
            //addChild(new Bitmap(source));
            //
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            System.pauseForGCIfCollectionImminent(1);
            init();
            stats = new AwayStats(view);
            addChild(stats);
            stats.x = 340;
        }

        private function init():void {
            view = new View3D();
            scene = view.scene;
            camera = view.camera;
            addChild(view);
            light = new PointLight();
            scene.addChild(light);
            setup();
            initialize();
            //
            addEventListener(Event.ENTER_FRAME, render, false, 0, true);
        }
        private function setup():void {
            view.backgroundColor = 0x000000;
            view.antiAlias = 4;
            //
            camera.x = 0;
            camera.y = 0;
            camera.z = - radius;
            //
            light.x = 0;
            light.y = 0;
            light.z = 0;
            light.specular = 0.1;
            light.diffuse = 0.9;
            light.ambient = 0.2;
        }
        private function initialize():void {
            var geometry:CubeGeometry = new CubeGeometry(20, 20, 20, 1, 1, 1, false);
            var bitmapData:BitmapData = new BitmapData(2, 2, false, 0xFFFFFFFF);
            var texture:BitmapTexture = new BitmapTexture(bitmapData);
            var material:TextureMaterial = new TextureMaterial(texture);
            var lightPicker:StaticLightPicker = new StaticLightPicker([light]);
            material.lightPicker = lightPicker;
            for (var n:uint = 0; n < max; n++) {
                var cube:Mesh = new Mesh(geometry, material);
                cube.x = (Math.random() - 0.5)*500;
                cube.y = (Math.random() - 0.5)*500;
                cube.z = (Math.random() - 0.5)*500;
                cube.rotationX = Math.random()*360;
                cube.rotationY = Math.random()*360;
                cube.rotationZ = Math.random()*360;
                scene.addChild(cube);
            }
        }
        private function render(evt:Event):void {
            angle += 0.5;
            degree += 1;
            var dip:Number = depression*Math.sin(degree*radian);
            camera.x = radius*Math.cos(angle*radian)*Math.cos(dip*radian);
            camera.y = radius*Math.sin(dip*radian);
            camera.z = radius*Math.sin(angle*radian)*Math.cos(dip*radian);
            camera.lookAt(center);
            view.render();
            //view.renderer.queueSnapshot(source);
        }

    }

}