Steiner Chain 03
...
@author 9re
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aCI8
*/
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author 9re
*/
[SWF(backgroundColor="#000000", frameRate="29")]
public class DocumentClass extends MovieClip
{
private var _scale:Number = 20;
private var _n:int = 12;
private var _cx:Number;
private var _cy:Number;
private var _circles:Array = [];
private var _t:Number = 0;
private var _a:Number;
private var _rho:Number;
private var _r:Number;
private var X:Number = 0.1;
private var Y:Number = -0.2;
public function DocumentClass()
{
var r:Number = 0.7;
_a = Math.PI / _n;
_rho = r * Math.sin(_a) / (1 - Math.sin(_a));
_a = 2 * _a;
var s:Number;
_r = r + _rho;
_cx = stage.stageWidth / 2;
_cy = stage.stageHeight / 2;
var sp:Sprite;
for (var i:int = 0; i < _n; ++i)
{
sp = new Sprite();
sp.graphics.beginFill(0xffffff, (i + 1) / _n);
sp.graphics.drawCircle(0, 0, _rho * _scale);
sp.graphics.endFill();
addChild(sp);
_circles.push(sp);
}
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(e:Event):void
{
var sp:Sprite;
var t:Number;
for (var i:int = 0; i < _n; i++)
{
t = _t + i * _a;
sp = _circles[i];
placeCircle(sp, X + _r * Math.cos(t), Y + _r * Math.sin(t), _rho);
}
_t += Math.PI / 30;
}
private function placeCircle($circle:Sprite, cx:Number, cy:Number, cr:Number):void {
var c:Number = cx * cx + cy * cy - cr * cr;
var rx:Number, ry:Number, rr:Number;
$circle.x = cx / c * _scale + _cx;
$circle.y = -cy / c * _scale + _cy;
$circle.scaleX = $circle.scaleY = cr / c / _rho;
}
public function draw(cx:Number, cy:Number, cr:Number):void {
var c:Number = cx * cx + cy * cy - cr * cr;
var rx:Number, ry:Number, rr:Number;
rx = cx / c * _scale + _cx;
ry = -cy / c * _scale + _cy;
rr = cr / c * _scale;
graphics.drawCircle(rx, ry, rr);
}
}
}