Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random Color Change at Layer Marker (with transition)?

  • Random Color Change at Layer Marker (with transition)?

    Posted by Rob Frese on June 16, 2015 at 4:51 pm

    Hey guys — searched around but can’t find an answer to this.

    How can I create a random color change at each layer marker that transitions between the colors?

    In other words, it doesn’t just abruptly cut to a different color, it changes to that color over the course of a couple of frames? Like if you just keyframed a color property?

    I have an expression yields a random color change at each layer marker, when applied to the HUE property of the Color Balance (HLS) effect (see below) but this just cuts to the new color, no transition.

    I don’t nearly have the intelligence to put together something like this, but it would be GREATLY appreciated.

    Thanks,
    Rob

    markerLayer = thisComp.layer(1);
    m = markerLayer.marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }

    seedRandom(n,true);
    random([n*81.79],[n*n*7.77])

    Ido Shor replied 6 years, 4 months ago 5 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 16, 2015 at 5:28 pm

    Try this:


    tRamp = 3*thisComp.frameDuration;
    markerLayer = thisComp.layer(1);
    m = markerLayer.marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }

    seedRandom(n,true);
    c1 = random([n*81.79],[n*n*7.77]);

    if (n > 0){
    seedRandom(n-1,true);
    c0 = random([(n-1)*81.79],[(n-1)*(n-1)*7.77]);
    t = time - m.key(n).time;
    linear(t,0,tRamp,c0,c1)
    }else{
    c1
    }

    Dan

  • Rob Frese

    June 16, 2015 at 8:59 pm

    Dan! Yes! Perfect! Exactly what I needed.

    Wow, I didn’t know Dan Ebberts would be answering my question. That’s pretty freaking cool.

  • Juanluis Vich

    August 10, 2016 at 2:25 am

    hi!
    do you know if it’s possible to take the color from a selection from a bunch of Color Control effect (maybe stored at the same layer) instead of a total random color? I’ve been trying to, but not lucky at all 🙁

    thanks!

  • Santi Agustí

    August 10, 2016 at 3:14 pm

    it is not the cleanest, but you can apply this to a fill effect:

    markerLayer = thisLayer
    m = markerLayer.marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }

    seedRandom(n,true);
    color1=thisComp.layer("Colors").effect("Color Control")("Color");
    color2=thisComp.layer("Colors").effect("Color Control 2")("Color");
    color3=thisComp.layer("Colors").effect("Color Control 3")("Color");
    color4=thisComp.layer("Colors").effect("Color Control 5")("Color");
    //etc

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

    idx = Math.floor(random(colors.length));
    colors[idx]

  • Ido Shor

    January 1, 2020 at 9:26 am

    Hey Dan, and all the rest… :)))

    I encountered an error while trying to use this expression:
    “expression result must be of dimension 4, not 1”

    any clues?

    also… while you are at it, will be nice if you can send a version of the script that doesn’t have a transition within.

    thanks!!
    Ido.

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