SpiroGraph 01
SpiroGraph
@author taiga
スピログラフの式
x[θ0] = (r0-r1) Cos[θ0] + r2 Cos[θ0+θ1];
y[θ0] = (r0-r1) Sin[θ0] + r2 Sin[θ0+θ1];
θ1 = -(r0/r1) θ0
r0:穴の半径
r1:円盤の半径
r2:円盤のペン穴までの半径
θ0:円盤の位置を穴の中心より見た角度
θ1:円盤の回転する角度
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
/**
* SpiroGraph
* @author taiga
* スピログラフの式
* x[θ0] = (r0-r1) Cos[θ0] + r2 Cos[θ0+θ1];
* y[θ0] = (r0-r1) Sin[θ0] + r2 Sin[θ0+θ1];
* θ1 = -(r0/r1) θ0
*
* r0:穴の半径
* r1:円盤の半径
* r2:円盤のペン穴までの半径
* θ0:円盤の位置を穴の中心より見た角度
* θ1:円盤の回転する角度
*/
[SWF (backgroundColor="#ffffff", frameRate="30", width="500", height="500")]
public class SpiroGraph extends Sprite {
private const R :Number = 250;
private var _shape1 :CircleShape;
private var _shape2 :CircleShape;
private var _shape3 :CircleShape;
private var _baseCircle01 :BaseCircle;
private var _baseCircle02 :BaseCircle;
private var _baseCircle03 :BaseCircle;
private var _timer :Timer;
private var r0 :Number;
private var r1 :Number;
private var r2 :Number;
private var t1 :Number;
private var t0 :Number;
private var t0_ :Number;
private var t0__ :Number;
private var _d :Number;
[SWF (backgroundColor="#ffffff", frameRate="30")]
public function SpiroGraph() {
super();
var sw_:Number = stage.stageWidth;
var sh_:Number = stage.stageHeight;
with(graphics) {
beginFill(0xffffff);
drawRect(0, 0, sw_, sh_);
beginFill(0x333333);
drawCircle(sw_ / 2, sh_ / 2, 250);
endFill();
}
_shape1 = new CircleShape();
_shape2 = new CircleShape();
_shape3 = new CircleShape();
_baseCircle01 = new BaseCircle();
_baseCircle02 = new BaseCircle();
_baseCircle03 = new BaseCircle();
_timer = new Timer(10);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
r0 = 250;
r1 = 120;
r2 = 70;
t1 = 0;
t0 = 0;
t0_ = 120 * Math.PI / 180;
t0__ = 240 * Math.PI / 180;
_d = 0.03;
addChild(_shape1);
addChild(_shape2);
addChild(_shape3);
addChild(_baseCircle01);
addChild(_baseCircle02);
addChild(_baseCircle03);
_timer.start();
}
private function timerHandler(event:TimerEvent):void {
drawGraph();
event.updateAfterEvent();
}
private function drawGraph():void {
t0 -= _d;
t1 = -(r0 / r1) * t0;
_shape1.x = ((r0-r1) * Math.cos(t0) + r2 * Math.cos(t0 + t1)) + R;
_shape1.y = ((r0-r1) * Math.sin(t0) + r2 * Math.sin(t0 + t1)) + R;
t0_ -= _d;
t1 = -(r0 / r1) * t0_;
_shape2.x = ((r0-r1) * Math.cos(t0_) + r2 * Math.cos(t0_ + t1)) + R;
_shape2.y = ((r0-r1) * Math.sin(t0_) + r2 * Math.sin(t0_ + t1)) + R;
t0__ -= _d;
t1 = -(r0 / r1) * t0__;
_shape3.x = ((r0-r1) * Math.cos(t0__) + r2 * Math.cos(t0__ + t1)) + R;
_shape3.y = ((r0-r1) * Math.sin(t0__) + r2 * Math.sin(t0__ + t1)) + R;
_baseCircle01.x = (R-r1) * Math.cos(t0) + R;
_baseCircle01.y = (R-r1) * Math.sin(t0) + R;
_baseCircle02.x = (R-r1) * Math.cos(t0_) + R;
_baseCircle02.y = (R-r1) * Math.sin(t0_) + R;
_baseCircle03.x = (R-r1) * Math.cos(t0__) + R;
_baseCircle03.y = (R-r1) * Math.sin(t0__) + R;
}
}
}
import flash.display.Shape;
class CircleShape extends Shape {
public function CircleShape() {
super();
graphics.beginFill(0xffffff);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
}
class BaseCircle extends Shape {
public function BaseCircle() {
super();
graphics.beginFill(0x999999, 0);
graphics.drawCircle(0,0,120);
graphics.endFill();
}
}