うんどう
円運動
/**
* Copyright Kihara ( http://wonderfl.net/user/Kihara )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/eZoc
*/
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
[SWF(backgroundClr="0x000000",width="465", height="465")]
public class flash_ex07_sample3 extends Sprite
{
private var ball1:Ball;
private var ball2:Ball;
private var ball3:Ball;
private var ball4:Ball;
private var ball5:Ball;
private var ball6:Ball;
private var radius:Number=0;
private var centerX:Number=stage.stageWidth / 2;
private var centerY:Number=stage.stageHeight / 2;
private var r:Number=200;
public function flash_ex07_sample3()
{
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
ball1=new Ball(0xFF0000); //赤い玉
ball1.x=centerX + r;
ball1.y=centerY;
ball2=new Ball(0x00FF00); //緑の玉
ball2.x=centerX + r;
ball2.y=centerY;
ball3=new Ball(0x0000FF); //青の玉
ball3.x=centerX;
ball3.y=centerY + r;
ball4=new Ball(0x00FFFF); //水色の玉
ball4.x=centerX - r;
ball4.y=centerY;
ball5=new Ball(0xFF00FF);//紫の玉
ball5.x=centerX - r;
ball5.y=centerY;
ball6=new Ball(0xFFFF00);//黄色の玉
ball6.x=centerX;
ball6.y=centerY - r;
addChild(ball1);
addChild(ball2);
addChild(ball3);
addChild(ball4);
addChild(ball5);
addChild(ball6);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
//角度をちょっとづつ増やしてやる
radius+=3;
graphics.clear(); //線を毎回消す
//赤い玉を動かす
ball1.x=r * Math.cos(Math.PI * radius / 180) + centerX;
ball1.y=r * Math.sin(Math.PI * radius / 180) + centerY;
//緑の玉を動かす
ball2.x=r * Math.cos(Math.PI * radius / 180) + centerX;
//青の玉を動かす
ball3.y=r * Math.sin(Math.PI * radius / 180) + centerY;
//水色の玉を動かす
ball4.x=-r * Math.cos(Math.PI * radius / 180) + centerX;
ball4.y=-r * Math.sin(Math.PI * radius / 180) + centerY;
//紫の玉を動かす
ball5.x=-r * Math.cos(Math.PI * radius / 180) + centerX;
//黄色の玉を動かす
ball6.y=-r * Math.sin(Math.PI * radius / 180) + centerY;
draw_line(); //線を毎回描く
}
private function draw_line():void
{
graphics.lineStyle(1, 0xFFFFFF);
//緑と青を結ぶ
graphics.moveTo(ball2.x, ball2.y);
graphics.lineTo(ball3.x, ball3.y);
//赤と青を結ぶ
graphics.moveTo(ball1.x, ball1.y);
graphics.lineTo(ball3.x, ball3.y);
//赤と緑を結ぶ
graphics.moveTo(ball1.x, ball1.y);
graphics.lineTo(ball2.x, ball2.y);
//紫と黄色を結ぶ
graphics.moveTo(ball5.x, ball5.y);
graphics.lineTo(ball6.x, ball6.y);
//水色と黄色を結ぶ
graphics.moveTo(ball4.x, ball4.y);
graphics.lineTo(ball6.x, ball6.y);
//水色と紫を結ぶ
graphics.moveTo(ball4.x, ball4.y);
graphics.lineTo(ball5.x, ball5.y);
//青と紫を結ぶ
graphics.moveTo(ball3.x, ball3.y);
graphics.lineTo(ball5.x, ball5.y);
//緑と黄色を結ぶ
graphics.moveTo(ball2.x, ball2.y);
graphics.lineTo(ball6.x, ball6.y);
//円を描く
graphics.drawCircle(centerX, centerY, 200);
//縦の線
graphics.moveTo(centerX, centerY + 200);
graphics.lineTo(centerX, centerY - 200);
//横の線
graphics.moveTo(centerX + 200, centerY);
graphics.lineTo(centerX - 200, centerY);
}
}
}
import flash.display.Sprite;
class Ball extends Sprite
{
public function Ball(color:Number)
{
graphics.beginFill(color);
graphics.drawCircle(0, 0, 20);
graphics.endFill();
}
}