4 Replies Latest reply on Oct 13, 2014 6:35 AM by Rick Gerard

# Change color stroke expression

Hi everybody,

I´m using the stroke effect applying on a mask with a wave wrap effect. I have a music track with a "convert audio to keyframes" done.

I´d like to vary the stroke color with the speed of the music.

If the music accelerate, the stroke will pass to red, and when the music slows, it´ll converrt to green.

Have you got a expression to help me? There is another way to do this without expression?

Tks a lot and have a good wee!

• ###### 1. Re: Change color stroke expression

Facts:

• Your audio to keyframes produces a range of values that you can easily see using the graph editor
• The range of values that Audio to Keyframes generate denote volume not tempo
• Color values can be driven by an expression
• Color values are an array of 4 values from 0 to 1
• The array that would produce pure red looks like this [1, 0, 0, 1]
• The array that would produce pure green looks like this [0, 1, 0, 1]
• The linear expression function converts one range of numbers to another for example: linear(t, 0, 100, 1, 0) as the value of the property t changes from 0 to 100 the output changes from 1 to 0
• Since there is no automatic beat counter in AE and expressions pull values from the current frame, devising a mathematical formula that looked for the time difference between the loudest volumes in the timeline would not only be difficult to create mathematically it would take longer to calculate for frame 20 than it took to calculate for frame 10 the easiest solution would be to simply add an expression control slider to the layer and animate the value based on your perception of the tempo

If you wanted to emphasize the beats instead of the tempo the same expression could be driven from the keyframe values of the Audio To Keyframes layer left, right, or both channels. Change the range of the first set of values to correspond to the minimum and maximum values you observe in the graph editor.

Here is an expression for driving a color change with an expression control slider named more green.

t = effect("More Green")("Slider"); // slider value

r = linear(t, 0, 100, 2, 0); // value of red

g = linear(t, 0, 100, 0, 2); // value of green

[r, g, 0, 1]

Note: to prevent the luminance value falling to 50% when the slider is at a value of 50 the upper value must be set to 2 instead of 1. Color will clip the value at 1 unless the project is set to 16 or 32 bit. Even with a 32 bit project the color will appear normal unless you are using a blend mode on the layer.

An easier solution that would maintain luminance as the color values shift would be to add Hue and Saturation to your Fill effect, set it to Colorize and then animate hue.

• ###### 3. Re: Change color stroke expression

Tks a lot for the explication!
I´m not used to expressions and i feel a bit dizzy with it

When you say: "

Here is an expression for driving a color change with an expression control slider named more green.

t = effect("More Green")("Slider"); // slider value

r = linear(t, 0, 100, 2, 0); // value of red

g = linear(t, 0, 100, 0, 2); // value of green

[r, g, 0, 1]"

That means, i have to copy that to my slider? Which effect has to call "more green"?

I suceed to oscillate the color to white to black but not green to red

Tks for pacience!

• ###### 4. Re: Change color stroke expression
1. Add Effect>Expression Controls>Slider Control to the layer with Stroke applied.
2. In the Effects Control Panel select Slider Control, press Ender and rename it More Green
3. Alt/Option click on the Stroke Color stopwatch in the Effects Control Panel and paste the expression in the field that comes up
4. Drag the slider from 0 to 100 to have the color change from Red to Green

As an alternate to using this expression simply add Effect>Color Correction>Hue Saturation to the Stroke layer, select colorize and animate the hue.