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 2011-2-20

--My Sphere of Spheres example
--CONTROLS:
CLICK reo rerandomize colors and speeds
MOUSE X/Y changes Lighting X/Y
MOUSE WHEEL changes Lighting Z
Get Adobe Flash player
by mfc314159 20 Feb 2011
    Embed
/**
 * Copyright mfc314159 ( http://wonderfl.net/user/mfc314159 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nxCu
 */

package {
	//--My Sphere of Spheres example
	//--CONTROLS:
	// 		CLICK reo rerandomize colors and speeds
	// 		MOUSE X/Y changes Lighting X/Y
	// 		MOUSE WHEEL changes Lighting Z
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
  
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.core.effects.*;
    import org.papervision3d.core.effects.utils.*;
    import org.papervision3d.view.layer.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.view.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.materials.shaders.FlatShader;
    import org.papervision3d.materials.shaders.ShadedMaterial;
	

    public class Mainsouth extends Sprite {
        private const piE:Number = Math.PI / 180;
        //--PAPERVISION  it's tasty		
	private var viewport:Viewport3D;        
        private var scene:Scene3D;        
	private var renderer:BasicRenderEngine;        
	private var camera:Camera3D;
        
        //Yo dawg I heard you like spheres
        //So we put a sphere in your sphere 
        //so you can sphere while you sphere
        private var baseSphere:Sphere;
	private var subSpheres:Array = [];
	private var sphere:DisplayObject3D;
	

        //--BASE SPHERE
        private var baseSize:int = 400;
	private var baseSegs:int = 12;
	
        //--SUB SPHERES	
	private var subSize:int = 40;
	private var subSegs:int = 6;
        
        
        //--Ring holder
	private var rings:Array = [];
        private var vs:Array = [];
        private var vc:int;
	private var i:int = 0;
        private var id:int = 0;
        //Some light please!!		
	private var light:PointLight3D;
	private var angle:Number = 0;
	
		
        public function Mainsouth() {
                //Papervision INIT
		viewport = new Viewport3D();
		viewport.opaqueBackground = 0x000000;
		viewport.viewportWidth = 1000; 
		viewport.viewportHeight = 700;
		viewport.x = ( this.stage.stageWidth - viewport.viewportWidth ) / 2; 
		viewport.y = ( this.stage.stageHeight - viewport.viewportHeight ) / 2;
		addChild(viewport);
		scene = new Scene3D();
		camera = new Camera3D();
		renderer = new BasicRenderEngine();  
		//lighting
	      	light = new PointLight3D(true);
		light.x = 250;
		light.y = 250;
		light.z = -250;
		//scene.addChild(light);
			
		
		//Take yer places ya'll
		generateSpheres();
			
		//yeeee hawww
		stage.addEventListener(MouseEvent.MOUSE_DOWN, changeSpheres);
		stage.addEventListener(MouseEvent.MOUSE_WHEEL, lightZ);
		addEventListener(Event.ENTER_FRAME, loop);
        }
	private function generateSpheres():void {
		//--the whole sha-bang
		sphere = new DisplayObject3D();
		//--build Sphere to get vertice from
		baseSphere = new Sphere(null, baseSize, baseSegs, baseSegs);
               //--Get vertice info
		vs = baseSphere.geometry.vertices;
                vc = vs.length;
	        i = 0; //-------SETUP RINGS--
                //
		// rings[idx]	[ 0 ] = subSphere Container ie. "ring"
        	//		[ 1 ] = Array of subSpheres index# in container 
		//		[100] = ring color
		//		[101] = ring material
		//		[102] = ring yaw speed
		//		[103] = ring size
		while(i < baseSegs+1) {
			rings[i] = new Array(); //everything rings
			rings[i][0] = new DisplayObject3D(); //ring container
			rings[i][1] = new Array();
			rings[i][100] = Number(Math.random() * 0xFFFFFF); //random ring color
			//ring[i][10]] = whatever material
			//rings[i][101] = new WireframeMaterial(rings[i][100], 1, .1);
			//rings[i][101] = new ColorMaterial(rings[i][100], 1, false);
			rings[i][101] = new FlatShadeMaterial(light, rings[i][100], 0x000000, 10);
					
			//ring yaw speed
			rings[i][102] = Number(.33 + (Math.random() * 10));
			rings[i][102] *= .33; //yaw speed modifer
			rings[i][103] = subSize;
			i++;
		}
		i = 0;// --SETUP subSPHERES--
		while(i < vc) {
			//find ring index from y 
			var idx = int(.5 * (baseSegs + (baseSegs * (vs[i].y / baseSize))));
			//build sphere with ring props						
        		subSpheres[i] = new Sphere(rings[idx][101], rings[idx][103], subSegs, subSegs-1);
			//add to ring
			rings[idx][0].addChild(subSpheres[i]);
			rings[idx][1].push(i);
			//set sphere to vertix postion
			subSpheres[i].x = vs[i].x;
			subSpheres[i].y = vs[i].y;
			subSpheres[i].z = vs[i].z;
			//subSpheres[i].geometry.vertices[0].y -= 50.00;
			
			//
			i++;
		}
		
		i = 0;// --ADD RINGS TO SPHERE CONTAINER--
		while(i < rings.length) {
			sphere.addChild(rings[i][0]);
                            
			i++;
		}
		scene.addChild(sphere); //Sphere to the set please
		sphere.z = -125;// a little down.. thank you.
		
	}
	
	private function loop(e:Event):void {
		//-----MAIN LOOP
		//
		//
		i = 0;
		light.x = mouseX;
		light.y = mouseY; 
		while(i < rings.length) {
			rings[i][0].yaw(rings[i][102]);
			i++;
		}
		sphere.roll(.5);
		
		renderer.renderScene(scene, camera, viewport);
   	}
	private function lightZ(evt:MouseEvent) {
		light.z += (3 * evt.delta);
		//trace(light.z);
	}
	private function changeSpheres(evt:MouseEvent) {
		// rerandomize ring settings and reapply to subSpheres
		
		i = 0; // --SETUP RINGS--
		
		while(i < rings.length) {
			rings[i][100] = Number(Math.random() * 0xFFFFFF); //random ring color
			rings[i][101] = FlatShadeMaterial(light, rings[i][100], 0x000000, 10);
					//
			//ring yaw speed
			rings[i][102] = Number(.33 + (Math.random() * 10));
			rings[i][102] *= .33; //yaw speed modifer
							
			id = 0;
			while(id < rings[i][1].length) {
				subSpheres[ rings[i][1][id] ].material = rings[i][101];
				id++;
			}
			i++;
		}
	}//function
    }//class
}//package