Fibonacci test
Fibonacci Number test
@author naoto koshikawa
package
{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
/**
* Fibonacci Number test
* @author naoto koshikawa
*/
public class Fibonacci extends MovieClip
{
// _____________________________________________________ Property
/** material sum */
public static const MATERIAL_SUM:uint = 300;
/** material radius */
public static const MATERIAL_RADIUS:uint = 3;
/** material position start offset */
public static const CENTER_OFFSET:uint = 10;
/** base object */
private var _base:Sprite;
// _____________________________________________________ Method
/**
* constructor
*/
public function Fibonacci()
{
_base = new Sprite();
_base.x = stage.stageWidth / 2;
_base.y = stage.stageHeight / 2;
addChild(_base);
for (var i:uint = 0; i < Fibonacci.MATERIAL_SUM; i++)
{
var material:DisplayObject = circle();
var angle:Number = i * Math.PI * 2.0 * ((1 + Math.sqrt(5)) / 2);
material.x = (i+Fibonacci.CENTER_OFFSET) * Math.cos(angle);
material.y = (i+Fibonacci.CENTER_OFFSET) * Math.sin(angle);
_base.addChild(material);
}
addEventListener(Event.ENTER_FRAME, enterFrameListener);
}
/**
* get Shape object which present Circle
* @return Shape object
*/
private function circle():Shape
{
var s:Shape = new Shape();
var g:Graphics = s.graphics;
g.beginFill(Math.random() * 0x111111 + 0xEEEEEE);
g.drawCircle(0, 0, Fibonacci.MATERIAL_RADIUS);
return s;
}
// _____________________________________________________ Listener
/**
* enter frame event listener
* @param event
*/
private function enterFrameListener(event:Event):void
{
for (var i:uint = 0; i < _base.numChildren; i++)
{
var material:DisplayObject = _base.getChildAt(i);
var angle:Number = Math.atan2(material.y, material.x) + (0.1 * Math.PI/180);
material.x = Math.sqrt(material.x*material.x + material.y *material.y) * Math.cos(angle);
material.y = Math.sqrt(material.x*material.x + material.y *material.y) * Math.sin(angle);
}
}
}
}