Hi,
Can I store the colorGroupSwatches in 'myColorArray'? So I can pick a random color, delete it from the array (with splice), and repeat untill there are no more items in the array (array.length)
//example array
myColorArray = [
[100,0,0,0],[0,100,0,0],[0,0,100,0],[0,0,0,100]
];
for ( var i=0 ; i<myColorArray.length; i++ ) {
var randomFromArray = Math.floor(Math.random()*myColorArray.length);
var myRandomColor = myColorArray[randomFromArray];
//do something, for example fill a square with that color
// remove the color we selected so it can't be selected next time.
myColorArray.splice(randomFromArray,1);
}
Hi @studiovanzwet, if you want the colors in an Array, you can put them in one:
var myColors = [];
for (var i = 0;i < doc.colorGroups[1].colorGroupSwatches.length; i++)
myColors.push(doc.colorGroups[1].colorGroupSwatches[i].swatchItemRef);
// now we have the colors in an Array
// so we can use any Array method
var firstColor = myColors.shift();
- Mark