Copy link to clipboard
Copied
Hey, I would like to select a text frame and use a script so that each letter gets randomly coloured with one of the swatches out of my panel.
Does a script like this exist?
Thanks for any tips
here you go:
(function(){
var tf=app.activeDocument.selection[0];
var chars=tf.characters.everyItem().getElements();
var col=app.activeDocument.swatches.length-1;
for (var i=0; i<chars.length; i++){
var rand=Math.floor((Math.random() * col) + 1);
chars.fillColor=app.activeDocument.swatches[rand];
}
}());
Copy link to clipboard
Copied
here you go:
(function(){
var tf=app.activeDocument.selection[0];
var chars=tf.characters.everyItem().getElements();
var col=app.activeDocument.swatches.length-1;
for (var i=0; i<chars.length; i++){
var rand=Math.floor((Math.random() * col) + 1);
chars.fillColor=app.activeDocument.swatches[rand];
}
}());
Copy link to clipboard
Copied
Awesome, thank you.
Copy link to clipboard
Copied
One more question. To avoid the black, white and non colour [which can't be deleted] - is it possible that the script only use colours out of a group?
Cheers
Copy link to clipboard
Copied
Resurrecting a very old thread to say:
chars is missing its iterator in the last line due to forum migration. It should begin chars[i] for anyone stumbling across it now.