Copy link to clipboard
Copied
I'm trying to use a gradient as a control layer to rotate a 3d layer from 0 to 90 degrees. I'm still trying to wrap my head around expressions and thought doing a linear() to convert the number sample would work, but I'm stumped at this error. Am I trying to do the impossible or am I missing something simple that I just don't see? HELP!!
Copy link to clipboard
Copied
Sample image always returns an array, you're not actualyl deriving the luminance and well, your whole syntax on the last line is pretty nonsensical. A little cleanup and more explicit references easily can improve behavior:
mTarget=thisComp.layer("XYZ");
mPos=thisLayer.transform.position;
mSampleRGB=mTarget.sampleImage([mPos[0],mPos[1]],[.5,.5]);
mSampleHSL=rgbToHsl(mSampleRGB);
linear(mSampleHSL[2],0,1,0,90)
Mylenium
Copy link to clipboard
Copied
The nonsense in the last line was my failed beginner coders attempt to figure out what turns out to be rgbToHsl (which in hindsight makes perfect sense.) At least I was correct about missing something that someone with more experience would be able identify. This seems to work quite well to get the comp to do what I was hoping it would do, thank you much.
Copy link to clipboard
Copied
I would simplify the expression even farther. The Sample Method image returns an array of four decimal values with a range of zero to 1 for [Red, Green, Blue, Alpha]. Anything above 1 is greater than the maximum value that can be displayed on your screen. All you have to do is pick one and use that in the interpolation operator. If the gradient had a red value that changes from 0 to 1 as reported in the Info Panel or the color picker when the Info Panel is set to display decimal color values, all you have to do just return the red channel value from the sample image operator by adding [0] at the end. The working expression looks like this:
target = thisComp.layer("Gradient");
t = target.sampleImage(position, [.5, .5])[0];
linear(t, 0, 1, 0, 90)
Sample image has four values it looks at, but it only needs two of them unless you specifically need to have the color sample be taken before an effect has been applied to the layer or you want to sample at a specific time. If you wanted to average the color that was 100 pixels in diameter before any effects were applied to the target you could change this:
target.sampleImage(position, radius = [.5, .5], postEffect = true, t = time)[0];
to this:
target.sampleImage(position, [50, .50], false, 2)[0];
leaving the identifiers and the equal sign out of the expression simplifies troubleshooting when you come back to it but the function does not change.
There is no real need to change the RGBA output to HLS unless you specifically what to average all of the color values.
For reference, these are the values in the array:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now