我正在爲Adobe Illustrator編寫腳本以使用所選顏色填充對象。用顏色填充對象的腳本 - 均勻分佈,但沒有可辨別的模式
我有32個物體和12個顏色色板。我想用兩種顏色填充32個對象,然後用隨機選擇填充剩餘的8個對象。我想以不可辨別的模式填充對象,因此只需遍歷每個對象並將其分配給下一個樣本顏色就行不通。
這是我迄今爲止,但它不是至少兩次使用每種顏色和隨機填充。
myObjects = app.activeDocument.selection;
myDocument = app.activeDocument;
if (myObjects instanceof Array) {
colourSwatches = myDocument.swatches.getSelected();
//if there are swatches
if (colourSwatches.length != 0) {
for (i = 0; i < myObjects.length; i++) {
//if the selection is a path or compound path
if (myObjects[i].typename == "PathItem" || myObjects[i].typename == "CompoundPathItem") {
selItem = myObjects[i];
selItem.filled = true;
//select colour from swatches at random and then fill
swatchIndex = Math.round(Math.random() * (colourSwatches.length - 1));
if (selItem.typename == "PathItem") {
selItem.fillColor = colourSwatches[swatchIndex].color;
} else {
selItem.pathItems[0].fillColor = colourSwatches[swatchIndex].color;
}
}
}
}
}
非常感謝! – user1876246