Skip to main content
New Participant
January 20, 2014
Question

Script for randomly replacing characters with alternates for natural handdrawn look

  • January 20, 2014
  • 3 replies
  • 1075 views

I have been looking for a script for a comic book project. What I would like the script to do is to randomly find and change for example some of the "E"s to alternates in the font. Is that possible? Does anybody know if it exists? I’ve been looking quite hard - and no luck. Back in 2009 somebody was discussing something similar - but not quite what I am looking for.

Best regards from Denmark....

This topic has been closed for replies.

3 replies

January 23, 2014

Somewhere around here, I ran across this snippet for flipping a coin:

Math.floor(Math.random() * 2);

which returns either a 0 or a 1 , with long-term odds of roughly 50-50. But randomly.

So you find an e, then flip the coin to decide whether or not to change it. Repeat.

Inspiring
January 24, 2014

Hi

Maybe something like that :

-----------------

var myDoc = app.activeDocument;

var myStories = myDoc.stories.everyItem();

for (var i = 0; i < myStories.characters.length ; i++) {

     if(myStories.characters.contents == "\u0065" && Math.floor(Math.random() * 2)) {

          myStories.characters.contents = "\u005B";

     }

}

-----------------

Just replace the unicode that you want (here for the exemple "\u005B" is the left bracket).

You can also adapt the script from this topic (http://forums.adobe.com/message/6022683#6022683 - with the same idea but in wich you don't need to loop through all the characters of all your stories but just make a findGrep on your "e").

-----------------

app.findGrepPreferences = null;

doReplacement("\u0065");

function doReplacement(f) {

    app.findGrepPreferences.findWhat = f;

    var found = app.documents[0].findGrep();

    for (var i = found.length - 1; i >= 0; i--) {

        if (Math.floor(Math.random() * 2)) {

            found.contents = "\u005B";

        }

    }

}

-----------------

Message was edited by: LeftHead

Jump_Over
Brainiac
January 21, 2014

Dan R. Knudsen wrote:

I have been looking for a script for a comic book project. What I would like the script to do is to randomly find and change for example some of the "E"s to alternates in the font...

Hi,

Could you paste some example of your goal, pls.

Jarek

The Gothamite
Known Participant
January 21, 2014

What you could do is use FindReplaceByList to this, but you'll not get a truly random thing for this. However, you can manually define the Es that will need replacing, by encasing them in some sort of special character that rarely used. Granted, it's not the prettiest solution, but it works and it retains a human element.

For my example, I'll use the ■ (ALT+254). So let's say, you have the word Leeds. And you want the second E to be the other E. So you'd write Le■e■ds in your text.

  • Find out the ASCII Code of your Special E. Because it needs a different one.
  • Open your FindReplaceByList
  • Add a line like this to it:
    grep{findWhat:"■.■*"}{changeTo:"[ASCII-Code of your Special E]"}


New Participant
January 21, 2014

Well - then I would have to go trough all my text and put in the special characters where I would like different e’s - then I might as well put in the special e in the first place. I was looking for something that combined the automation with randomization. But thanks for sharing your thought on the topic ...