周波数の違う振り子を一斉にスタート
周波数の違う振り子を一斉にスタートさせるとそのうち一瞬だけ、また元の1列にならぶという物理の実験
ほんとに並んでるのかよくわからない
package
{
import flash.display.*;
import flash.events.Event;
[SWF(width=465,height=465,backgroundColor=0x000000,frameRate=60)]
public class ASTest extends Sprite
{
private const AMPLITUDE:Number = 40;
private const MIN_LENGTH:Number = 100;
private const LENGTH_INTERVAL:Number = 20;
private const NUM_PENDULUMS:int = 5;
private var _array:Array;
public function ASTest()
{
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(evt:Event = null):void
{
_array = new Array();
for(var i:int = 0; i < NUM_PENDULUMS; i++)
{
var pendulum:Pendulum = new Pendulum(AMPLITUDE, MIN_LENGTH + LENGTH_INTERVAL * i, Math.random()*0xffffff);
addChild(pendulum);
pendulum.x = Math.floor(stage.stageWidth/2);
pendulum.y = 100;
//pendulum.start();
_array.push(pendulum);
}
addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(evt:Event):void
{
for(var i:int = 0; i < _array.length; i++)
{
var p:Pendulum = _array[i] as Pendulum;
p.onEnter();
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
class Pendulum extends Sprite
{
private var _amp:Number;
private var _length:Number;
private var _color:uint;
private var _radian:Number = 0;
private var _omega:Number = 0;
private const DEF_LENGTH:Number = 10;
private const DEF_OMEGA:Number = 0.4;
private const RADIUS:Number = 10;
public function Pendulum(amplitude:Number = 20, length:Number = 300, color:uint = 0xffffff)
{
_amp = amplitude;
_length = length;
_color = color;
_omega = Math.sqrt(DEF_LENGTH/_length)*DEF_OMEGA;//たぶん
init();
}
private function init():void
{
this.graphics.clear();
this.graphics.beginFill(_color);
this.graphics.drawCircle(0,_length, RADIUS);
this.graphics.endFill();
this.graphics.lineStyle(1,_color);
this.graphics.moveTo(0,0);
this.graphics.lineTo(0,_length);
}
public function start():void
{
addEventListener(Event.ENTER_FRAME, onEnter);
}
public function onEnter(evt:Event = null):void
{
_radian += _omega;
var newX:Number = Math.sin(_radian)*_amp;
var newY:Number = Math.sqrt(_length*_length - newX*newX);
this.graphics.clear();
this.graphics.beginFill(_color);
this.graphics.drawCircle(newX,newY, RADIUS);
this.graphics.endFill();
this.graphics.lineStyle(1,_color);
this.graphics.moveTo(0,0);
this.graphics.lineTo(newX,newY);
}
}