-
How do I use the value calculated by an expression in a previous frame? (Wind Speed Map)
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
radius = 30*speedvalue;
angle = degreesToRadians(360*directionvalue);
deltax = radius*Math.sin(angle);
deltay = radius*Math.cos(angle);//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]