Skip to main content
Known Participant
August 3, 2016
Question

change color according to value

  • August 3, 2016
  • 1 reply
  • 2716 views

Hey.

I want to make an expression for a randomly changing number, (so far so good), but each time it will change a value, I want it to change color relatively to the previous value it had. MEANING... if it will goes up, then it will change to blue and if down then to orange (for example).

one more thing. I want it to change value every few seconds and do it with a "hold interpolation" so it will jump to the next value instead of working it's way toward it...

now.. so far I got this: (for the first part anyway)

-----------------------------------------------------------------------------------------------------------------------------

upColor = thisComp.layer("Ctrl").effect("Up Color")("Color");

downColor = thisComp.layer("Ctrl").effect("Down Color")("Color");

value = thisComp.layer("Ctrl").effect("Slider Control")("Slider");

prevframe = thisComp.layer("Ctrl").effect("Slider Control")("Slider").valueAtTime(time - thisComp.frameDuration);

if(prevframe.valueAtTime < ((time * 25) % 2 == 0).valueAtTime))downColor else upColor;

value;

-----------------------------------------------------------------------------------------------------------------------------

any ideas?

thanks!

Ido.

This topic has been closed for replies.

1 reply

UQg
Legend
August 3, 2016

Hello,

'value' is a reserved word for expressions. It represents the key value (that is, pre-expression) of the current property and cannot be overridden by something else.

Try replacing 'value' by say 'x'. It might very well be that your expression is correct other than that.

Xavier

idoshorAuthor
Known Participant
August 3, 2016

so, if I get you right it should be something like this:

upColor = thisComp.layer("Ctrl").effect("Up Color")("Color");

downColor = thisComp.layer("Ctrl").effect("Down Color")("Color");

X = thisComp.layer("Ctrl").effect("Slider Control")("Slider");

prevframe = X.valueAtTime(time - thisComp.frameDuration);

if(prevframe.valueAtTime < ((time * 25) % 2 == 0).valueAtTime))downColor else upColor;

X;

UQg
Legend
August 3, 2016

Thanks Xavier, Finally made a real progress here.

what I encountered now is something I didn't think of.... when the number is staying the same, the colour is changing to the "true" colour of the "if" expression. meaning the result inside the brackets.

how do I tell it to stay the same until the next change?

almost there.....


This should work:

upColor = thisComp.layer("Ctrl").effect("Up Color")("Color");

downColor = thisComp.layer("Ctrl").effect("Down Color")("Color");

X = thisComp.layer("Ctrl").effect("Slider Control")("Slider");

ta = time - thisComp.frameDuration;

a = X.valueAtTime(ta);

b = X.value;

while (a===b && ta>=inPoint){

    b=a;

    ta -= thisComp.frameDuration;

    a = X.valueAtTime(ta);

    };

if (b<a) downColor else upColor;

The way it is written you can't really control the initial color (at inPoint). It would require some slight modification for that.

And as Mathias said, it can be slow if the slider value doesnt vary for long periods.

Xavier