ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Combine 2 Character Sets in a Single Expression?

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Keith CleversleyCombine 2 Character Sets in a Single Expression?
by on Oct 31, 2010 at 11:44:34 pm

Hello all,

After ending up at this forum often with my inevitable After Effects newbie questions, one that I can't find an answer to anywhere has prompted me to join the forum.

QUESTION: I want to animate the "Character Value" or the "Character Range" using an expression that will randomly choose between 2 different ranges or characters.

EFFORTS: Using "random(1,10)" in both "Character Value" or "Character Range" to return a random range of characters between 1 and 10. Perfect!

But, I want to have the result return a value from 2 DIFFERENT ranges. In other words, I want to return a range of characters from 1-10 as well as a range of characters from 20-30, skipping 11-19.

So, I tried "random([1, 10], [20, 30])" and every other combination I could think of or find examples of on the web. But, I got an error every time. Mostly the error tells me that the "expression result must be of dimension 1, not 2." That makes sense, but I still can't figure out how to get my final output to be both a range from 1-10, as well as a range from 20-30, skipping 11-19.

Hope this is clear; if not, just let me know, and thanks in advance as well. I look forward to sometime having something to give back the to the community!

Best,
Keith


Return to posts index

Dave LaRondeRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 3:11:01 pm

I recommend visiting the AE Expressions forum with your question:
http://forums.creativecow.net/adobe_after_effects_expressions

Dave LaRonde
Sr. Promotion Producer
KCRG-TV (ABC) Cedar Rapids, IA


Return to posts index

Kevin CampRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 3:23:56 pm

[Keith Cleversley] "I tried "random([1, 10], [20, 30])""

you were on the right track, but since the input was an array, returned value will be an array, and you will need to pick which value of the array you want ae to use...

think of your multidimensional array like x,y position values... you're telling ae to pick a random x from one range, and a random y from another range. then you need to tell ae that you want to see either x or y.

something like this should work:
r1=[1,10]; // array for 1st range of random numbers
r2=[20,30]; // array for 2nd range of random numbers
n=random([r1[0],r2[0]],[r1[1],r2[1]]); // this creates a 2-dimensional random number array
a=Math.floor(random(0,2)); this creates a random value to choose which part of the array (0 or 1) to display
n[a];


Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index


Kevin CampRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 3:29:09 pm

actually, change that 4th line to something like this:

a=Math.round(random(0,1));
this way there is no chance to return a 2, which would be an invalid value for the array (that would be the 3rd dimension of the array).

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

Keith CleversleyRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 5:18:39 pm

"I recommend visiting the AE Expressions forum with your question"

Will do next time; I figured all newbie basic questions went here.

And Kevin: That worked like a dream; thanks! Never expected such a fast response.

Now, out of curiosity only (my question is already answered), is there a way to make the array choose from the first set (1-10) twice as often as the second set (20-30)?

Not important, just curious and thanks again.

Best,
Keith


Return to posts index

Kevin CampRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 6:55:03 pm

a direct way could be to add the r1 array one more time the random value arrays...

n=random([r1[0],r1[0],r2[0]],[r1[1],r[1,1],r2[1]]); // this creates a 3-dimensional random number array
a=Math.floor(random(0,3));

in this case Math.floor() may be better than Math.round() since .5 and 1.49 value would be 1, and lesser values 0, greater values 2 (essentially 1 is twice as likely as either 0 to 2 if you round).

or try keeping all the original code, but change the 4th line to:
a=Math.floor((random(0,3)/2));
which would seem to make it 2x as likely for a value of 0 to be returned as a 1, making the first array value occur 2x as often.

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index


Keith CleversleyRe: Combine 2 Character Sets in a Single Expression?
by on Nov 1, 2010 at 7:06:01 pm

The first expression makes more sense to my newbie brain, but the simple elegance of the second one is what I used. And, it's sits right around 2 to 1 ratio, just as you suspected.

Thanks again!

Best,
Keith


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]