Activity › Forums › Adobe After Effects Expressions › comparing 4 values?
-
comparing 4 values?
Posted by Erin Shelby on August 28, 2010 at 1:29 amI found an expression to compare two values here:(https://forums.creativecow.net/readpost/227/12294). I was wondering if there was a way to do this with four values? ie:
if a>b>c>d then
else
if b>a>c?d then…seems slightly unelegant
https://forums.creativecow.net/readpost/227/12294Dan Ebberts replied 15 years, 8 months ago 2 Members · 4 Replies -
4 Replies
-
Dan Ebberts
August 28, 2010 at 2:35 amIt really depends on exactly what you’re trying to do. JavaScript provides a number of options. Can you give an example of how you would use this?
Dan
-
Erin Shelby
August 29, 2010 at 12:22 amYes, basically I have four values on 4 different expression sliders. They will constantly be differing values, but depending on which value is the highest I want a text layer to be a certain color. So (in pseudo code) ideally it would be something like:
if
x is highest = make this text layer green
y is highest = make this text layer yellow
z is highest = make this text layer blue
w is highest = make this text layer redFilip’s code works for two values, but four is a bit more perplexing. Do i have to nestle the statements?
Also, I am not sure how to determine the colors exact values using the odd [1,1,1,0] format of after effects. I have the RGB values, is the conversion just divided by 255?
Thanks for all your help thus far.
Erin.
-
Dan Ebberts
August 29, 2010 at 1:01 amThere must be a simpler way to do this, but this seems to work:
if (x >= y && x >= z && x >= w){
c = [0,255,0,255];
}else if (y >= x && y >= x && y >= w){
c = [255,255,0,255];
}else if (z >= x && z >= y && z >= w){
c = [0,0,255,255];
}else{
c = [255,0,0,255];
}
c/255;
Dan
-
Dan Ebberts
August 29, 2010 at 9:10 amI like this better:
t1 = Math.max(x,y);
c1 = x > y ? [0,255,0,255] : [255,255,0,255];
t2 = Math.max(z,w);
c2 = z > w ? [0,0,255,255] : [255,0,0,255];
t1 > t2? c1/255 : c2/255
Dan
Reply to this Discussion! Login or Sign Up