Highlighted

## After Effect expression

New Here ,
Jan 29, 2018

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 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

Views

205

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more ## After Effect expression

New Here ,
Jan 29, 2018

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 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

Views

206

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Jan 29, 2018 0
Engaged ,
Jan 29, 2018

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;

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Jan 29, 2018 0