var doc = app.activeDocument;
    var artboard = doc.artboards[0];
    var artboardRect = artboard.artboardRect;
    var circles = [];
    for (var i = 0; i < numCircles; i++) {
        var radius = Math.random() * 50 + 10; 
        // ランダムなサイズ(10〜60の範囲)
        var x, y, overlapping;
        do {
            overlapping = false;
            x = Math.random() * (artboardRect[2] - 
                artboardRect[0] - 2 * radius) + 
                artboardRect[0] + radius;
            y = Math.random() * (artboardRect[1] - 
                artboardRect[3] - 2 * radius) + 
                artboardRect[3] + radius;
            for (var j = 0; j < circles.length; j++) {
                var dx = circles[j].x - x;
                var dy = circles[j].y - y;
                var distance = Math.sqrt(dx * dx + dy * dy);
                if (distance < circles[j].radius + radius) {
                    overlapping = true;
                    break;
                }
            }
        } while (overlapping);
        var circle = doc.pathItems.
            ellipse(y + radius, x - radius, 2 * radius, 2 * radius);
        circle.filled = true;
        circle.fillColor = new CMYKColor();
        circle.fillColor.cyan = Math.random() * 100;
        circle.fillColor.magenta = Math.random() * 100;
        circle.fillColor.yellow = Math.random() * 100;
        circle.fillColor.black = Math.random() * 0;
        //Blackを利用するとダークな結果になるので利用していません
        circle.stroked = false; // 線なし
        circles.push({ x: x, y: y, radius: radius });
    }
}
var numCircles = 
    prompt("作成する円の数を入力してください:", "20");
if (numCircles !== null) {
    createRandomCircles(parseInt(numCircles, 10));
}
実行したら円の数を入力します。デフォルトは20。ただし40以上になるとIllustratorが落ちるかも・・・
結果A
結果 B




 
 
 

 
