/**
* Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/488L
*/
// forked from Tamanegi_kenshi's forked from: forked from: forked from: forked from: forked from: flash on 2010-1-11
// forked from Tamanegi_kenshi's forked from: forked from: forked from: forked from: flash on 2010-1-11
package {
import flash.events.MouseEvent;
import flash.accessibility.Accessibility;
import flash.display.Sprite;
import flash.events.Event;
public class test extends Sprite{
private var ball:BALL;
private var ballNum:uint=50;
private var fl:int=250;
private var stX:Number=stage.stageWidth/2;
private var stY:Number=stage.stageHeight/2;
private var top:Number=-stY+20;
private var bottom:Number=stY-20;
private var left:Number=-stX+20;
private var right:Number=stX-20;
private var front:Number=250;
private var back:Number=-250;
private var balls:Array;
private var easing:Number=0.1;
public function test(){
init();
}
private function init():void{
balls=new Array();
for(var i:uint=0;i<ballNum;i++){
ball=new BALL(50,Math.random()*0xffffff);
ball.posx=Math.random()*300-150;
ball.posy=Math.random()*200-100;
ball.posz=Math.random()*200-150;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME,onEnter);
}
private function onEnter(e:Event):void{
var angleY:Number=(mouseX-stX)*0.001;
var angleX:Number=(mouseY-stY)*0.001;
for(var i:uint=0;i<ballNum;i++){
var ball:BALL=balls[i];
rotatoY(ball,angleY);
rotatoX(ball,angleX);
move(ball);
}
sortz()
}
private function rotatoY(ball:BALL, angleY:Number):void{
var cos:Number=Math.cos(angleY);
var sin:Number=Math.sin(angleY);
var x1:Number=cos*ball.posx-sin*ball.posz;
var z1:Number=cos*ball.posz+sin*ball.posx;
ball.posx=x1;
ball.posz=z1;
}
private function rotatoX(ball:BALL, angleX:Number):void{
var cos:Number=Math.cos(angleX);
var sin:Number=Math.sin(angleX);
var y1:Number=cos*ball.posy-sin*ball.posz;
var z1:Number=cos*ball.posz+sin*ball.posy;
ball.posy=y1;
ball.posz=z1;
}
private function move(ball:BALL):void{
var scale:Number=fl/(fl+ball.posz);
ball.scaleX=ball.scaleY=scale;
ball.x=stX+ball.posx*scale;
ball.y=stY+ball.posy*scale;
}
private function sortz():void{
balls.sortOn("posz",Array.NUMERIC | Array.DESCENDING);
for(var i:uint=0;i<ballNum;i++){
var ball:BALL=balls[i];
setChildIndex(ball,i);
}
}
}
}
import flash.display.Sprite;
class BALL extends Sprite{
public var radius:int;
public var color:uint;
public var vx:Number =0;
public var vy:Number =0;
public var vz:Number =0;
public var posx:Number=0;
public var posy:Number=0;
public var posz:Number=0;
public var tx:Number=0;
public var ty:Number=0;
public var tz:Number=0;
public function BALL(radius:int=10,color:uint=0x000000){
this.radius =radius;
this.color =color
graphics.lineStyle(0);
graphics.beginFill(color);
graphics.drawRect(radius/2,radius/2,radius,radius);
graphics.endFill();
}
}