Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- After Effects
- >
- Re> After Effect expression

Highlighted

New Here
,

Jan 29, 2018

Copy link to clipboard

Copied

Hi, I have trouble getting this to work:

r = random(5)

if (r == 0)

[226, 6, 19, 1]

else if (r ==1)

[148, 27, 128, 1]

else if (r ==2)

[242, 145, 0, 1]

else if (r ==3)

[252, 234, 13, 1]

else if (r ==4)

[0, 149, 64, 1]

else

[53, 168, 224, 1]

Simply want to randomly select one of these 6 colors for my stroke. That's it, someone can help me ??

Thanks

Engaged

If you applied "random(5)" to somehing like a text layer's source text, you'll see that it doesn't produce whole numbers but rather numbers with decimal places in the range from 0 to 5 (in this case). So you'd be better off using "if (r < 1)" and so on (or alternatively using some rounding method on r like Math.round()"

Also, the text layer test would show that the results of random change on every frame which may not be what you want, in which case adding "seedRandom(seed = index, timeless = true)" at the start of the expression would fix that. In this case I'm telling it to use the layer number (index) as a random seed value and have the result not dependant on time (i.e. a static value).

Finally, color values need to be in the range of 0-1 not 0-255, so you wouldn't be getting the results you expect as anything greater than 1 will essentially be treated as 255 in 8bpc terms. Easiet thing here is just to divide your numbers by 255.

seedRandom(seed = index, timeless = true);

r = random(6)

if (r < 1) [226, 6, 19, 1] / 255;

else if (r < 2) [148, 27, 128, 1] / 255;

else if (r < 3) [242, 145, 0, 1] / 255;

else if (r < 4) [252, 234, 13, 1] / 255;

else if (r < 5) [0, 149, 64, 1] / 255;

else [53, 168, 224, 1] / 255;

TOPICS

Expressions

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

New Here
,

Jan 29, 2018

Copy link to clipboard

Copied

Hi, I have trouble getting this to work:

r = random(5)

if (r == 0)

[226, 6, 19, 1]

else if (r ==1)

[148, 27, 128, 1]

else if (r ==2)

[242, 145, 0, 1]

else if (r ==3)

[252, 234, 13, 1]

else if (r ==4)

[0, 149, 64, 1]

else

[53, 168, 224, 1]

Simply want to randomly select one of these 6 colors for my stroke. That's it, someone can help me ??

Thanks

Engaged

If you applied "random(5)" to somehing like a text layer's source text, you'll see that it doesn't produce whole numbers but rather numbers with decimal places in the range from 0 to 5 (in this case). So you'd be better off using "if (r < 1)" and so on (or alternatively using some rounding method on r like Math.round()"

Also, the text layer test would show that the results of random change on every frame which may not be what you want, in which case adding "seedRandom(seed = index, timeless = true)" at the start of the expression would fix that. In this case I'm telling it to use the layer number (index) as a random seed value and have the result not dependant on time (i.e. a static value).

Finally, color values need to be in the range of 0-1 not 0-255, so you wouldn't be getting the results you expect as anything greater than 1 will essentially be treated as 255 in 8bpc terms. Easiet thing here is just to divide your numbers by 255.

seedRandom(seed = index, timeless = true);

r = random(6)

if (r < 1) [226, 6, 19, 1] / 255;

else if (r < 2) [148, 27, 128, 1] / 255;

else if (r < 3) [242, 145, 0, 1] / 255;

else if (r < 4) [252, 234, 13, 1] / 255;

else if (r < 5) [0, 149, 64, 1] / 255;

else [53, 168, 224, 1] / 255;

TOPICS

Expressions

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

simeonb28446397

Jan 29, 2018
0
/t5/after-effects/after-effect-expression/td-p/9713746
1
Reply
1

Engaged
,

Jan 29, 2018

Copy link to clipboard

Copied

If you applied "random(5)" to somehing like a text layer's source text, you'll see that it doesn't produce whole numbers but rather numbers with decimal places in the range from 0 to 5 (in this case). So you'd be better off using "if (r < 1)" and so on (or alternatively using some rounding method on r like Math.round()"

Also, the text layer test would show that the results of random change on every frame which may not be what you want, in which case adding "seedRandom(seed = index, timeless = true)" at the start of the expression would fix that. In this case I'm telling it to use the layer number (index) as a random seed value and have the result not dependant on time (i.e. a static value).

Finally, color values need to be in the range of 0-1 not 0-255, so you wouldn't be getting the results you expect as anything greater than 1 will essentially be treated as 255 in 8bpc terms. Easiet thing here is just to divide your numbers by 255.

seedRandom(seed = index, timeless = true);

r = random(6)

if (r < 1) [226, 6, 19, 1] / 255;

else if (r < 2) [148, 27, 128, 1] / 255;

else if (r < 3) [242, 145, 0, 1] / 255;

else if (r < 4) [252, 234, 13, 1] / 255;

else if (r < 5) [0, 149, 64, 1] / 255;

else [53, 168, 224, 1] / 255;

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Reply

Loading...

Paul Tuersley

Jan 29, 2018
0
/t5/after-effects/after-effect-expression/m-p/9713747#M53041
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.