Created
June 5, 2016 08:28
-
-
Save shspage/f52083ffd0e7af2a2f9205cb007aa026 to your computer and use it in GitHub Desktop.
Illustrator script (Commented in Japanese)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 円周に等間隔配置.jsx | |
// 円に沿って、何かをだいたい決まった間隔で配置します。 | |
// 沿わせる円と、配置したい何かを選んで実行。 | |
// ※ 配置は 90度の位置(円の上端)から始まります。 | |
function main(){ | |
var sel = app.activeDocument.selection; | |
if(sel.length < 2) return; | |
var m = prompt("配置間隔は幅の何倍?", 1.5); | |
if(!m) return; | |
var c = sel[0]; // 沿わせる円(仮) | |
var target = sel[1]; // 何か(仮) | |
if(target.width > c.width){ // 何かの方が大きければ逆にする | |
c = [target, target = c][0]; | |
} | |
var gb = c.geometricBounds; | |
var radius = (gb[2] - gb[0]) / 2; // 半径 | |
var circumference = 2 * Math.PI * radius; // 円周 | |
var interval = target.width * m; // 配置間隔 | |
// 円周を間隔で割って整数に丸める | |
var count = Math.round(circumference / interval); | |
// 結果の角度(ラジアン) | |
var tUnit = (Math.PI * 2) / count; | |
var cCenter = getCenter(c); // 円の中心 | |
var targetCenter = getCenter(target); // 何かの中心 | |
var HPI = Math.PI / 2; // 90度 | |
// 配置 | |
for(var i = 0; i < count; i++){ | |
var d = target.duplicate(); | |
var t = tUnit * i + HPI; // 90度の位置から始める | |
d.translate(Math.cos(t) * radius + cCenter[0] - targetCenter[0], | |
Math.sin(t) * radius + cCenter[1] - targetCenter[1]); | |
d.rotate((t - HPI) * 180 / Math.PI); | |
} | |
} | |
// 中心の位置を求める | |
function getCenter(p){ | |
var gb = p.geometricBounds; // left, top, right, bottom | |
return [(gb[0] + gb[2]) / 2, (gb[1] + gb[3]) / 2]; | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment