Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions How to change random colors gradually?

  • How to change random colors gradually?

  • Gerben Greuliker

    November 25, 2022 at 12:18 pm

    I’ve found this great rig for randomizing preset colors.
    It’s made by Andrew Marston of Ukramedia and it works perfectly.

    The only trouble with this rig is that it doesn’t blend the colors from one color to another.
    Is there a simple solution to gradually change to another random color?

    The code is down below. The first is the more elaborate version of the code. At the bottom is a simplified (and less flexible) version.

    The Youtube video which explains the build is found here:

    https://www.youtube.com/watch?v=yIaARyBthBs

    colors = new Array();

    numColors = thisComp.layer("Ctrl").effect("numColors")("Slider");

    for(i = 1; i <= numColors; i++){

    newColor = thisComp.layer("Ctrl").effect("Color Control " + i)("Color");

    colors.push(newColor);

    }

    slider = thisComp.layer("Ctrl").effect("Freq")("Slider").value;

    counter = Math.floor(time/slider);

    seedRandom(counter, true);

    colorId = Math.floor(random(colors.length));

    colors[colorId];

    color1 = thisComp.layer("Ctrl").effect("Color Control 1")("Color");

    color2 = thisComp.layer("Ctrl").effect("Color Control 2")("Color");

    color3 = thisComp.layer("Ctrl").effect("Color Control 3")("Color");

    color4 = thisComp.layer("Ctrl").effect("Color Control 4")("Color");

    colors = [color1, color2, color3, color4];

    freq = thisComp.layer("Ctrl").effect("Freq")("Slider");

    counter = Math.floor(time/freq);

    seedRandom(counter, true);

    colorId = Math.floor(random(colors.length));

    colors[colorId];

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Filip Vandueren

    November 25, 2022 at 2:19 pm

    Try this Gerben:

    colors = new Array();
    numColors = thisComp.layer("Ctrl").effect("numColors")("Slider");
    for(i = 1; i <= numColors; i++){
    newColor = thisComp.layer("Ctrl").effect("Color Control " + i)("Color");
    colors.push(newColor);
    }
    slider = thisComp.layer("Ctrl").effect("Freq")("Slider").value;
    counter = Math.floor(time/slider);
    seedRandom(counter, true);
    fromColor = colors[Math.floor(random(colors.length))];
    seedRandom(counter+1, true);
    toColor = colors[Math.floor(random(colors.length))];
    ease((time/slider)%1,0,1,fromColor, toColor);

    Note that Frequency is actually duration per flash, not flashes per seconds.


    If you want to hold the colors for a little while before it interpolates, you could do this as the last line:

    ease((time/slider)%1, 0, 1/3, fromColor, toColor);

    which will ease for 1/3 of the time and hold 2/3 of the time.

  • Gerben Greuliker

    November 27, 2022 at 9:25 pm

    And again many thanks for the solution!

Viewing 1 - 3 of 3 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy