Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › How do I use the value calculated by an expression in a previous frame? (Wind Speed Map)

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

    Posted by Adam Cole on October 29, 2012 at 10:24 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
    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]

    Adam Cole replied 13 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 29, 2012 at 10:41 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

  • Adam Cole

    October 30, 2012 at 3:48 pm

    Thanks! I think I’ve figured out a simple way to accomplish what I want…

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy