ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Changing Color Based on Another Percentage Value

FAQ   •   VIEW ALL
 Changing Color Based on Another Percentage Value on Mar 29, 2019 at 7:06:13 pmLast Edited By Andrew Jones on Mar 30, 2019 at 10:10:57 am

Hi!

I have a shape that has a Trim Path that goes from 30% to 100%. I'd like to change its color from Green (RGB = 0,255,0) to Yellow (RGB=255,255,0) when it is at 65%, and then to Red (RGB=255,0,0).

However, I'd like a smooth transition of color, so the color gradually changes from Green to Yellow to Red as the shape's trim path changes.

Currently starting off, I've tried to do this:
[(100-content("Ellipse 1").content("Trim Paths 1").end),255,0,255]

But I noticed that the color is green as long as the trim path is 100%. If it goes to 99%, I get yellow directly.

What expression should I be using to make this work?

Thank you!

Edit: I just realized I can also use HSL with Hue from 120 -> 0 as the trim path end goes from 100 -> 30. However, I'm still not sure how to write the expression.

 Re: Changing Color Based on Another Percentage Valueon Mar 30, 2019 at 10:26:22 pm

Hue from 120 -> 0 as the trim path end goes from 100 -> 30.

Try this:
end = content("Ellipse 1").content("Trim Paths 1").end;
hslToRgb([linear(end, 30, 100, 0, 120/360), 1,0.5,1]);

 Re: Changing Color Based on Another Percentage Valueon Apr 1, 2019 at 3:20:45 pm

Thank you! That worked exactly as intended.

Quick question: I'm trying to understand expressions a little bit more. Why did the code I wrote not work?

 Re: Changing Color Based on Another Percentage Valueon Apr 1, 2019 at 3:31:24 pm

>Why did the code I wrote not work?
Well, color arrays in AE are arrays of numbers from 0 to 1 (at least, for 8bpc and 16bpc), i.e. Green=[0,1,0,1] and Yellow = [1,1,0,1]. So when you went from 100 to 99% you immediately switched from green to yellow.