Copy link to clipboard
Copied
I have an expression (pinched from an old creative cow post that in turn referenced a Dan Eberts expression) that decodes a string of text from a random selection of characters. It currently decodes the string from left to right and I need it to decode in a random order. Any ideas? Thanks in advance!
choices = "QAZWSXEDCRFVTGBYHNUJMIKOLP";
str = "this is my string";
tStart = 1; //time at which the animation starts
tStop = 2.4; //time at which the animation stop
cps = 0; // characters per second
if (time < tStart){
seed = Math.floor(time*cps);
seedRandom(seed,true);
s = "";
for (i = 0; i < str.length; i++){
idx1 = Math.floor(random(choices.length));
s += choices[idx1];
}
}
else if (time >= tStart && time < tStop){
seed = Math.floor(time*cps);
seedRandom(seed,true);
s = "";
sRand = "";
for (i = 0; i < str.length; i++){
idx1 = Math.floor(random(choices.length));
idx2 = Math.floor(linear(time,tStart,tStop,0,1)*str.length);
sRand += choices[idx1];
s = str.substr(0,idx2) + sRand.substr(idx2,str.length);
}
}else{
s = str;
}
s
1 Correct answer
Most of the time trying to do everything on one layer over complicates a project. Here's a solution a little outside the box:
1. Create a new text layer with your random characters
2. Create a new text layer with your final text
3. Create a new text layer with a symbol font to create a box for each letter
4. Adjust the scale and tracking of all text layers to line up the boxes with the other two text layers (easiest to do using the difference blend mode
5. Add Set Matte to the second and
...Copy link to clipboard
Copied
You would have to modify the idx2 variable to also be based on randomness rather than just time, though then there would be no way to ensure that you don't get duplicate hits on the same letters and each of them is only used once. That in itself would require yet another loop to collect and exclude already used characters. All that said, why not simply use a wiggly text selector to add some randomness on top of the linear motion? Might look good enough and would be simpler to do. You could even go so far as to entirely ditch the source text expression and just work with text animators, though admittedly that in itself is hard to grasp and tricky to get right.
Mylenium
Copy link to clipboard
Copied
This is essentially what I had been trying to do and failing miserably at! Thanks for the response Mylenium.
Copy link to clipboard
Copied
Random decoding of characters is much easier to do with text animators. You're making this much too difficult. There's even a decoder text preset that might get you started.
Copy link to clipboard
Copied
The issue I was running into with text animator, and specifically the decoder preset, was that it uses character offset so still has spaces in the same places and still has the capitalization of the underlying text string. I may not have delved deep enough however.
Copy link to clipboard
Copied
Most of the time trying to do everything on one layer over complicates a project. Here's a solution a little outside the box:
1. Create a new text layer with your random characters
2. Create a new text layer with your final text
3. Create a new text layer with a symbol font to create a box for each letter
4. Adjust the scale and tracking of all text layers to line up the boxes with the other two text layers (easiest to do using the difference blend mode
5. Add Set Matte to the second and third text layer and set the top symbol font text the source and invert one of the copies.
6. Add the Random Fade In-text preset to the top layer
Here's what that looks like:
If you use Monospaced fonts this is incredibly easy and quick to set up. Much faster than monkeying with expressions.
It took me about 10 minutes to do this. Here's the project file: https://www.dropbox.com/s/dchswxxyt8xsedh/Random%20Txt%20using%20mattes.aep?dl=0
(if your browser adds a .txt extension to the AEP file just delete it)
Copy link to clipboard
Copied
Thanks so much for this Rick!

