FORUMS: list search recent posts

How do I use the value calculated by an expression in a previous frame? (Wind Speed Map)

FAQ   •   VIEW ALL
 How do I use the value calculated by an expression in a previous frame? (Wind Speed Map) on Oct 29, 2012 at 10:24:43 pm

Hi!

I'm making an animated wind speed map. A bunch of moving dots will show how fast and in what direction the wind is moving. The idea is simple - the dots, which are placed evenly over the composition, will "read" speed and direction data from maps in layers below them with sampleImage. I made the images from weather station data in GIS - for the "Speed" map white is 5 mph, black is 100 mph; for the "Direction" image white is 0 degrees, and black is 360 degrees - different levels of gray for everything in between.

The goal is to have the dot move over the map based on the Speed and Direction data directly below it. My plan was to simply move the dots by adding this speed and direction values to

//reading the white/black value of the maps
target = thisComp.layer("Speed");
speedvalue = target.sampleImage(position, [5, 5])[0];
target = thisComp.layer("Direction");
directionvalue = target.sampleImage(position, [5, 5])[0];

//calcuting the change in position

//finding the position of the layer in the last frame
lastplace = position.valueAtTime(time-thisComp.frameDuration);

//updating the new x y value
x = lastplace[0]+deltax;
y = lastplace[1]+deltay;
[x,y]

But when I get "lastplace" it is always the original position of the dot - not where the dot was in the last frame. So the first frame works fine, but then it breaks down. Suggestions?

```target = thisComp.layer("Speed"); speedvalue = target.sampleImage(position, [5, 5])[0]; target = thisComp.layer("Direction"); directionvalue = target.sampleImage(position, [5, 5])[0]; radius = 30*speedvalue; angle = degreesToRadians(360*directionvalue); deltax = radius*Math.sin(angle); deltay = radius*Math.cos(angle); lastplace = position.valueAtTime(time-thisComp.frameDuration); x = lastplace[0]+deltax; y = lastplace[1]+deltay; [x,y]```

 Re: How do I use the value calculated by an expression in a previous frame? (Wind Speed Map)on Oct 29, 2012 at 10:41:31 pm

There's no way for an expression to retrieve a value it caclulated on a different frame. When an expression accesses the value of its host property using value or valueAtTime(), it gets the pre-expression value for that time. So, at each frame, your expression will have to loop through all previous frames to re-calculate the current conditions.

Using the time parameter of sampleImage() in your loop will help, but it's going to bog down if your comp is long.

Dan