Datasheet

Chapter 1: Understanding Flash3D
27
//The vertical angle between circles.
var phiStep:Number=30;
var phiTilt:Vector. < Number > =new Vector. < Number > ();
phiTilt=Vector. < Number > ([-90,-60,-30,0,30,60,90]);
//radius of the Sphere
var radius:Number=180;
//Stage Center
var CenterX:Number = stage.stageWidth/2;
var CenterY:Number = stage.stageHeight/2;
//Place Particles on the Stage
var i:int;
var j:int;
var tStep:Number;
var pStep:Number=phiStep*Math.PI/180;
for(i=0;i < 7;i++){
tStep=thetaStep[i]*Math.PI/180;
for(j=0;j < jLen[i];j++)
{
//Draw a plane
var plane:Sprite = new Sprite();//instantiates plane sprite
plane.graphics.beginFill(Math.random()*0xffffff);//Assign a plane color
plane.graphics.drawRect(-30, -30, 30, 30);//draws your plane at 0,0
plane.graphics.endFill();//ends the fill
//Add plane to the stage
myDisplayObject.addChild(plane);
//Use parametric equations of a sphere
plane.x = radius*Math.sin(i*pStep)*Math.sin(j*tStep);
plane.z = -radius*Math.sin(i*pStep)*Math.cos(j*tStep);
plane.y =-radius*Math.cos(i*pStep);
//Set rotations
plane.rotationX=phiTilt[i];
plane.rotationY=-j*thetaStep[i];
particles_ary.push(plane);
}
}
//Start Looping and Set Display Object
addEventListener(Event.ENTER_FRAME, myonEnterFrame);
addChild(myDisplayObject);
myDisplayObject.rotationX=0;
myDisplayObject.x=CenterX;
myDisplayObject.y=CenterY;
//Sorting
function sortParticles():void
{
particles_ary.sort(particleZSort);
for(var k:int = 0; k < particles_ary.length; k++)
{
(continued)
c01.indd 27c01.indd 27 12/14/09 3:03:32 PM12/14/09 3:03:32 PM