
Illustratorでスピログラフを描画させてみました。
■スピログラフのパラメータ
外側の固定円(半径 R)
内側の回転円(半径 r)
描画点の距離 d(内円の中心からの距離)
ステップ数 s(1ユニットのパス数)
角度 θ(回転角)
■スピログラフの方程式
スピログラフの曲線 (x, y) は、以下のパラメータ方程式で表されます。
基本形(ハイポサイクロイド)
x(θ)=(R-r)cos(θ)+d cos(((R-r)r)θ)
y(θ)=(R-r)sin(θ)-d sin(((R-r)r)θ)
ここで:
θ は回転角(0 から 2π × ループ回数 まで変化)
(R - r) の比が整数であれば閉じた軌跡になる
#target illustrator
function drawSpirograph(doc, centerX, centerY, R, r, d,
steps, rotations) {
var path = doc.pathItems.add();
path.stroked = true;
path.filled = false;
path.strokeWidth = 1;
var points = [];
for (var i = 0; i <= steps * rotations; i++) {
var theta = (Math.PI * 2 * i) / steps;
var x = (R - r) * Math.cos(theta) +
d * Math.cos(((R - r) / r) * theta);
var y = (R - r) * Math.sin(theta) -
d * Math.sin(((R - r) / r) * theta);
points.push([centerX + x, centerY + y]);
}
var pathPoints = path.pathPoints;
for (var j = 0; j < points.length; j++) {
var p = pathPoints.add();
p.anchor = points[j];
p.leftDirection = p.anchor;
p.rightDirection = p.anchor;
}
}
// ユーザー入力ダイアログを表示
function getUserInput() {
var dialog = new Window("dialog", "スピログラフ設定");
dialog.add("statictext", undefined, "外円の半径 (R):");
var RInput = dialog.add("edittext", undefined, "150");
RInput.characters = 5;
dialog.add("statictext", undefined, "内円の半径 (r):");
var rInput = dialog.add("edittext", undefined, "70");
rInput.characters = 5;
dialog.add("statictext", undefined, "ペンの距離 (d):");
var dInput = dialog.add("edittext", undefined, "100");
dInput.characters = 5;
dialog.add("statictext", undefined, "ステップ数:");
var stepsInput = dialog.add("edittext", undefined, "200");
stepsInput.characters = 5;
dialog.add("statictext", undefined, "回転数:");
var rotationsInput = dialog.add("edittext", undefined, "10");
rotationsInput.characters = 5;
var okButton = dialog.add("button",
undefined, "OK", {name: "ok"});
var cancelButton = dialog.add("button",
undefined, "キャンセル", {name: "cancel"});
var result = null;
okButton.onClick = function () {
result = {
R: parseFloat(RInput.text),
r: parseFloat(rInput.text),
d: parseFloat(dInput.text),
steps: parseInt(stepsInput.text, 10),
rotations: parseInt(rotationsInput.text, 10)
};
dialog.close();
};
cancelButton.onClick = function () {
result = null;
dialog.close();
};
dialog.show();
return result;
}
// メイン処理
function main() {
if (app.documents.length === 0) {
app.documents.add();
}
var doc = app.activeDocument;
var centerX = doc.artboards[0].artboardRect[2] / 2;
var centerY = doc.artboards[0].artboardRect[3] / 2;
var userInput = getUserInput();
if (!userInput) return;
drawSpirograph(doc, centerX, centerY, userInput.R, userInput.r,
userInput.d, userInput.steps, userInput.rotations);
}
main();
実行して、各パラメーターの値を入力すれば描画が実行されます。パスの塊です。
パラメーター変更例(その1)
パラメーター変更例(その2)
パラメーター変更例(その3)