flash on 2009-4-29
//////////////////////////////////////
//
奥行きを考慮した円運動の練習 //
クリックでスタート・ストップ //
//
//////////////////////////////////////
////////////////////////////////////////
// //
// 奥行きを考慮した円運動の練習 //
// クリックでスタート・ストップ //
// //
////////////////////////////////////////
package{
import flash.display.Sprite;
import flash.events.*;
[SWF(width = 465, height = 465, backgroundColor = 0xffffff, frameRate = 30)]
public class MoveCircle extends Sprite{
private const FIGURE_SIZE:uint = 10;
private const FIGURE_CNT:uint = 24;
private var figureArray:Array = new Array();
private var angles:Array = new Array();
private var flag:Boolean = false;
public function MoveCircle(){
init();
this.stage.addEventListener(MouseEvent.CLICK,startAndStop);
}
//円の作成
public function init():void{
var circle:Sprite;
var keisan:Keisan;
for(var i:uint ; i<FIGURE_CNT ; i++){
circle = new Sprite();
circle.graphics.beginFill(0xFFFFFF * Math.random());
circle.graphics.drawCircle(0, 0, FIGURE_SIZE);
circle.graphics.endFill();
keisan = new Keisan(i*15);
keisan.pointKeisan();
circle.x = keisan.EyeX;
circle.y = keisan.EyeY;
circle.alpha = keisan.EyeAlpha;
circle.scaleX = keisan.EyeZ;
circle.scaleY = keisan.EyeZ;
addChild(circle);
figureArray.push(circle);
angles.push(keisan.Angle);
}
}
//終点座標に配置
public function move(event:Event):void{
for(var j:uint=0;j<FIGURE_CNT;j++){
var keisan:Keisan = new Keisan(angles[j]);
keisan.pointKeisan();
figureArray[j].x = keisan.EyeX;
figureArray[j].y = keisan.EyeY;
figureArray[j].alpha = keisan.EyeAlpha;
figureArray[j].scaleX = keisan.EyeZ;
figureArray[j].scaleY = keisan.EyeZ;
angles[j] = keisan.Angle;
}
}
public function startAndStop(event:MouseEvent):void{
if(flag){
stage.removeEventListener(Event.ENTER_FRAME, move);
}else{
stage.addEventListener(Event.ENTER_FRAME, move);
}
flag=!(flag);
}
}
}
import flash.display.Sprite;
class Keisan extends Sprite{
private var circleZ:Number;
private var circleY:Number;
private var eyeX:Number;
private var eyeY:Number;
private var eyeZ:Number;
private var eyeAlpha:Number;
private var radian:Number;
private var angle:Number;
//基点
private var myStageWidth:Number = 150;
private var myStageHeight:Number = 220;
private const BALL_ANGLE:int = -1;
public function Keisan(angle:Number){
this.angle = angle;
}
public function get EyeX():Number{
return eyeX;
}
public function get EyeY():Number{
return eyeY;
}
public function get EyeZ():Number{
return eyeZ;
}
public function get EyeAlpha():Number{
return eyeAlpha;
}
public function get Angle():Number{
return angle;
}
public function pointKeisan():void{
//座標の算出
radian= Math.PI * angle / 180;
angle += BALL_ANGLE;
//z軸に半径300の円があるものとする
circleZ = 300 * Math.cos(radian);
circleY = 300 * Math.sin(radian);
//z=150に表示
eyeZ = 150 / ( 400 + circleZ );
eyeY = myStageHeight + (circleY * eyeZ);
eyeX = myStageWidth + (80 * eyeZ);
eyeAlpha = eyeZ + 0.1;
}
}