ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Sampling a range of colors to apply to layers based on their position...

FAQ   •   VIEW ALL
 Sampling a range of colors to apply to layers based on their position... on Apr 19, 2012 at 5:15:38 pm

Alright so I need some help with setting up expressions...

I have a cluster of layers (1000 of them) all randomly scattered (and moving) in 3D space. Basically like a school of fish. I want the closest objects to be white, while the farthest one is blue. And every one in between pulls from the color gradient of white>blue.

There are "falloff" presets available, like VideoCopilot for example, but these are all relative based on the camera's distance. I want to be able to move the camera, but have the color range stay in tact.

Now I am beginning with the method used in this Red Giant tutorial, where they use a color sampling expression to pull from set points on a gradient layer. I set up my gradient (white>blue) and set about 200 Point Controls to get vector data out of the colors. But how do I apply this color range to the position range of my objects?

Assuming my closest object has a max zPosition of -200 and the farthest object has a max zPosition of 200 (ranges I have set with expressions already), how do I say, for each layer, "Where is your position in the range of -200 to 200? Now change your color according to the color gradient specified"

-Chris

 Re: Sampling a range of colors to apply to layers based on their position...on Apr 19, 2012 at 10:11:35 pm

Simple fix is to scale the values and link them to a colour corrector on the layer. Tint amount or cOlor balance maybe?

 Re: Sampling a range of colors to apply to layers based on their position...on Apr 20, 2012 at 4:55:26 pm

Thanks Marcus,

Your simple solution worked perfectly. I didn't need the SampleImage expression at all. Instead, I placed a Tint on each layer, and modified the Tint Amount with an expression like this:

linear(position[2], -200, 200, 0, 100)

I am not very clear on what the linear() expression does... but it got the job done!

Thanks again

-Chris

 Re: Sampling a range of colors to apply to layers based on their position...on Apr 20, 2012 at 6:10:08 pm

[Chris Mellor] "linear(position[2], -200, 200, 0, 100)

I am not very clear on what the linear() expression does... but it got the job done!"

linear() interpolates a value (position[2]) from one range ([-200,200]) to another ([0,100]) along a straight line.

-200 is mapped to 0, 200 is mapped to 100, 0 is mapped to 50, etc. There's a hard start from -200 and a hard end to 200.

The ease() function works almost the same, except that it eases the beginning and ending so their velocities are 0.

The difference is the same as between linear and easy-eased keyframes.

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events