2017-03-08 4 views
3

図形のモザイクはIllustratorで一緒にフィットしていますが、現在はすべて白黒です。例えばイラストレーターで無作為に5色で図形を塗りつぶす

enter image description here

は、しかし、私はすでに、好ましくは、2つの色が隣にせずにランダムな順序で私は図形のそれぞれを埋めるために使用する一連の色を(持っています例えば

:それはのようなものを見えるように)互いに

enter image description here

モザイクは私の最初のファイルに250+個あり、2番目のファイルに800個以上あります。

答えて

1
/* 
    This script performs random color fill. 
    Select art items and colors in swatches panel and run script. 
    Note: neighbor art items can get the same colors. 
*/ 
var doc = app.activeDocument; 
var selItems = doc.selection; 
var sw_sel = doc.swatches.getSelected(); 
if (sw_sel.lenght==0) 
    exit; 

for (var i=0; i<selItems.length; i++) 
{ 
    var selItem = selItems[i]; 
    if(selItem.typename == "PathItem" || 
     selItem.typename == "CompoundPathItem") 
    { 
     var randomColorIdx = getRandom(0, sw_sel.length - 1); 
     setColor(selItem, sw_sel[randomColorIdx].color);     
    } 
} 

function setColor(pItem, color) 
{ 
    pItem.filled = true; 
    if(pItem.typename == "PathItem") 
      pItem.fillColor = color; 
    else 
     pItem.pathItems[0].fillColor = color;  
} 

function getRandom(min, max) 
{ 
    return Math.floor(Math.random() * (max - min + 1)) + min; 
} 
関連する問題