
Random Fixed Color Expression
This tutorial expands upon my previous tutorial on creating a random color expression. That expression randomly changed color of your shape layer, but you achieved values that were in between the range of colors you selected. This tutorial features expressions to help you randomly change between fixed colors and not get the in-between values.
First, we add color controls to our shape layer for each color that we want to appear. Then, we set an expression for our shape’s fill color and create variables for each and add those variables to an array. We can control the value of the array by adding a slider control, and then return the value of the array (which is determined by the slider).
Once you add Math.floor to your slider value to eliminate complexities when your slider value is not a whole number, you can control the color shown based on your slider value.
var color1 = effect(“Color Control 1”)(“Color”);
var color2 = effect(“Color Control 2”)(“Color”);
var color3 = effect(“Color Control 3”)(“Color”);
var color4 = effect(“Color Control 4”)(“Color”);
var color5 = effect(“Color Control 5”)(“Color”);
colors=[color1,color2,color3,color4,color5];
slider=Math.floor(effect(“Slider Control”)(“Slider”));
colors[slider];
To automate this, we need to do more. We must make a variable that makes this whole expression go. For this, we create a variable that is equal to Math.floor(time/slider). This creates a whole number value that is always changing and makes your slider value act as a throttle or speed control.
This expression needs to work in conjunction with seedRandom. The seedRandom method allows you to replay the same random movements every time. The seed value is the variable we just created above, and then we need to complete the seedRandom method with a timeless argument that is either true or false. In this case, we want to use true because that makes this timeless. By that, I mean it stays the same on each frame but still chooses a random value. If you select false, everything changes each frame, which is not what is needed in this instance.
Now we need another value that helps choose the color. Set this to Math.floor(random(colors.length)). This adds the randomness into the equation, and sets the confines of the randomness to the number of values in your array. Finally, we return the value of the colors, which in the variable just created.
var color1 = effect(“Color Control 1”)(“Color”);
var color2 = effect(“Color Control 2”)(“Color”);
var color3 = effect(“Color Control 3”)(“Color”);
var color4 = effect(“Color Control 4”)(“Color”);
var color5 = effect(“Color Control 5”)(“Color”);
colors=[color1,color2,color3,color4,color5];
slider=effect(“Slider Control”)(“Slider”);
engine=Math.floor(time/slider);
seedRandom(engine,true);
colorChoose=Math.floor(random(colors.length));
colors[colorChoose];
Speed of color change is regulated by the slider control value.
###
Enjoying this tutorial? Sign up now for the Creative COW Newsletter!

Sign up for the Creative COW newsletter and get weekly updates on industry news, forum highlights, inspirational tutorials, tips, burning questions, and more! Receive bulletins from the largest, longest-running community dedicated to supporting professionals working in film, video, and audio.
Enter your email address, a first and last name, and let us know what you’d like to see more of in the message!
Responses