FORUMS TUTORIALS FEATURES VIDEOS PODCASTS EVENTS SERVICES JOBS NEWSLETTER NEWS BLOGS
 ADOBE AFTER EFFECTS: Home Forum Basics Expressions Tutorials Podcasts AE Techniques Creative Cloud Debate FAQ

# Re: Color changes on velocity

COW Forums : Adobe After Effects Expressions

 Re: Color changes on velocityby Darby Edelen on May 28, 2012 at 11:20:21 pm

[Alain Lores] "
factor =5;
Math.abs(thisComp.layer("G").position.velocity[0])/factor;"

This is only sampling the X component of the velocity of your layer. Is that what you're after? You probably noticed that velocity has 2 or 3 components, these correspond to the rate of change on the X and Y (and Z on a 3D layer) axes. If you want to work with a single value, and you don't want to split the velocity into separate axes, then you probably want to use the "speed" property:

``` factor = 5; thisComp.layer("G").position.speed/factor; ```

The Math.abs() function is not necessary for the position speed.

[Alain Lores] "1. The object that samples the colors to the left over shoots in height sampling black color. This object moves higher in height the faster the dot moves. How can i clamp the vales so that the object doesn't go past a certain height value?"

There are a couple of ways to accomplish this. One would be to use the Math.min() function:

``` max = 500; factor = 5; s = thisComp.layer("G").position.speed/factor; Math.min(max, s); ```

Math.min() will return the smaller of the two values passed to it, so whenever "s" is greater than "max" it will return "max" effectively clamping the highest value returned to "max."

[Alain Lores] "2. Notice how the colors on the band of particles do not fade. Instead it's solid from one color to the next. This is the result of the object moving way too quickly from fast to slow. Is there a way to control the speed in which the object moves? For example, how can the values be "smoothed" so that as the object samples the color it's slow enough to gradient correctly on the band of particles."

There is a smooth() function you could use that may help in this case. You'll want to smooth() the position property of the sampler, but it may be more complicated than that depending on how you've set up the expressions.

Darby Edelen