Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Hard color change by expressions

  • Hard color change by expressions

    Posted by James Quetant on February 13, 2014 at 3:49 pm

    Hello. I’ve tried doing a search before posting & while I did find some assistance it is not what I was precisely looking for. I want a piece of audio to make hard color changes of an object using expressions.

    I found a thread where Mr. Dan Ebberts gave a very good expression which actually does the color change but it’s a gradual, almost gradient type of change, where I’m looking for a hard change. Like a hard green to blue change for example, as opposed to gradually changing from green to blue…

    If this has been answered in past threads I do apologize as I’ve searched & did not find what I was looking for.

    Thanks in advance for the help, it is much appreciated!!

    James Quetant replied 12 years, 3 months ago 2 Members · 19 Replies
  • 19 Replies
  • Dan Ebberts

    February 13, 2014 at 5:58 pm

    Are you looking for color changes based on the audio level? If so, this is a simple three-color example:

    aud = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    red = [1,0,0,1];
    green = [0,1,0,1];
    blue = [0,0,1,1];
    level2 = 15;
    level1 = 5;
    if (aud > level2)
    blue
    else if (aud > level1)
    green
    else
    red

    If you need more colors, I would use arrays to clean up the code. If you need the colors to change in response to a “beat” and stay changed, that’s a completely different story, and requires some threshold-detection and/or beat-counting code.

    Dan

  • James Quetant

    February 13, 2014 at 6:18 pm

    No, actually I have the colors I want it to change to, I just want the audio to drive it.

    I can’t locate the thread right now, but the expression I followed is below. That gives the gradual change I’m talking about

    maxAudio = 70;
    minColor = [255,205,47,255]/255;
    maxColor = [213,116,45,255]/255;
    aud = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    linear(aud,0,maxAudio,minColor,maxColor)

  • James Quetant

    February 13, 2014 at 6:21 pm

    No, actually I have the colors I want it to change to, I just want the audio to drive it.

    I can’t locate the thread right now, but the expression I followed was something like this;

    maxAudio = 70;
    minColor = [255,205,47,255]/255;
    maxColor = [213,116,45,255]/255;
    aud = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    linear(aud,0,maxAudio,minColor,maxColor)

  • Dan Ebberts

    February 13, 2014 at 6:35 pm

    OK, so that’s the behavior you don’t want. Please describe the behavior you do want.

    Dan

  • Dan Ebberts

    February 13, 2014 at 6:42 pm

    Try this:

    threshold = 10;
    minColor = [255,205,47,255]/255;
    maxColor = [213,116,45,255]/255;
    aud = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    if (aud < threshold) minColor else maxColor

    Dan

  • James Quetant

    February 13, 2014 at 6:58 pm

    ok. That did the hard change but it only happened once. I want the audio I’m using to drive its change, so like change to the beat.
    Now that I’m thinking about it, I would like them to change between 4 different colors. Driven by the audio

  • Dan Ebberts

    February 13, 2014 at 7:05 pm

    Add additional colors to the colors array.


    threshold = 10.0;

    colors = [[255,205,47,255]/255,[213,116,45,255]/255];

    audioLev = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");

    above = false;
    frame = Math.round(time / thisComp.frameDuration);
    n = 0;
    while (frame >= 0){
    t = frame * thisComp.frameDuration;
    if (above){
    if (audioLev.valueAtTime(t) < threshold){
    above = false;
    }

    }else if (audioLev.valueAtTime(t) >= threshold){
    above = true;
    n++;
    }
    frame--
    }

    colors[n%colors.length]

    Dan

  • James Quetant

    February 13, 2014 at 7:47 pm

    Hey Dan, thanks for the help so far. I tried using that expression & I still got the same response, just 1 color change and that’s it. I added 4 different values to the array

  • Dan Ebberts

    February 13, 2014 at 7:51 pm

    How many times does your audio go above 10?

  • James Quetant

    February 13, 2014 at 7:53 pm

    well my maxAudio was at 70

Page 1 of 2

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