Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Change colour of object from original to a selected number of colours randomly

  • Change colour of object from original to a selected number of colours randomly

  • Janoo Wasan

    November 21, 2021 at 6:25 pm

    I was wondering if there was a way to change the colour of an object from it’s original colour to a select few colours randomly. Say for example, the original colour is yellow and to randomly change it over time to red, blue, green (given specific RGB values).

     

    I’m familiar with the ‘random ()’ expression and using it within the Color Balance effect to manipulate and change the Hue of an object – but that randomly changes the colour, not to a specific set of colours. Is there an expression or way to change to only a few colour values?

     

    I’m wondering if this is possible with the ‘Change to Color’ effect, whereby you can change from original color to a specific colour and use the keyframes to time to change, but is there a way to do it from one colour to 3-4 different colours and in random sequence, rather than just keyframing from one color to the next?

  • Dan Ebberts

    November 21, 2021 at 7:11 pm

    Assuming you have the Change to Color’s From parameter set to the original color, you could do something like this:

    colors = [[36,244,246,255], [169,36,246,255],[246,234,36,255]]; // alternate colors

    dur = 1; // how often to change colors

    seed = Math.floor(time/dur);

    seedRandom(seed,true);

    idx = Math.floor(random(colors.length +1));

    idx < colors.length ? colors[idx]/255 : effect("Change to Color")("From")

  • Janoo Wasan

    November 27, 2021 at 2:42 am

    Hi Dan,

    Thanks for your reply. I tried another expression with the Fill Color effect. But I’m wondering how can I have the color start with the set color (which is the first color in the expression). Currently it alternates between the colours, but it starts with a white-ish color and I just want it to alternate between the 4 options.

    posterizeTime(4)

    options = [[240, 80, 233, 255], [73, 215, 0, 255], [233, 207, 202, 255], [0, 135, 202, 255]];

    //seedRandom(index, true);

    r = Math.floor(random(4));

    options[r]/255;

  • Dan Ebberts

    November 27, 2021 at 3:45 pm

    Maybe change this line:

    r = Math.floor(random(4));

    to this:

    r = time < .25 ? 0 : Math.floor(random(4));

  • Janoo Wasan

    November 27, 2021 at 5:56 pm

    Thanks Dan! That works well!

  • Janoo Wasan

    November 30, 2021 at 9:49 am

    I was wondering if there would be a way to make it so that both the first and last colour is the same (I.e. it starts with the first colour in the colour array, and when the sequence ends, it ends on the same colour) so as to be able to loop the entire sequence?

  • Dan Ebberts

    November 30, 2021 at 5:52 pm

    I’m not sure how long the sequence is supposed to be, but something like this maybe:

    posterizeTime(4)

    options = [[240, 80, 233, 255], [73, 215, 0, 255], [233, 207, 202, 255], [0, 135, 202, 255]];

    r = (time < .25 || time >= outPoint - .25) ? 0 : Math.floor(random(4));

    options[r]/255;

  • Janoo Wasan

    November 30, 2021 at 10:50 pm

    The sequence is actually 20 seconds long. I’ll try out the expression. I’m trying to make it loopable so the first and last frame look the same.

    I use a CC particle world effect as well to generate random particles across the 20 second sequence and was wondering if something like a loopOut expression would work for that?

Viewing 1 - 8 of 8 posts

Log in to reply.

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