Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Value out of a “while loop” decreases when it should not.

  • Value out of a “while loop” decreases when it should not.

    Posted by Alberto Brancolini on December 1, 2011 at 5:03 pm

    Hallo everyone.

    Here I’ve got a weird behavior -to me, at least- by an expression and I’d like to understand where’s the mistake I made.

    I wanted to have an esteem of the overall distance of a cycling course.
    After drawing a mask all along the roads, I pasted it to a null’s position and turned the comp’s framerate to 50 for a higher accuracy.
    Then I took Dan Ebbert’s (thank you, your website saves my life almost daily) expression for accumulating random values and I fitted it to my need. At the end, I divided for the maps scale.

    Now the fun part: the value sometimes decreases, expecially when the path bends.

    My knowledge is that a curve may not be represented correctly, but it’s still a vector between two points.

    So, can you tell me where’s my mistake?

    Thank you.

    j = 0; //counter
    dist = 0; //distance
    p1 = transform.position.valueAtTime(time);
    p0 = transform.position.valueAtTime(time-thisComp.frameDuration);

    while (j<time) {
    dist += length(p1-p0);
    j += thisComp.frameDuration;
    }
    dist/comp("scala").layer("Null 4").effect("fattoreConv")("Slider")/10;

    Alberto Brancolini replied 14 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    December 1, 2011 at 5:08 pm

    I think you need to put your p0 and p1 definitions inside the loop (and use j instead of time).

    Dan

  • Alberto Brancolini

    December 1, 2011 at 6:27 pm

    Thank you very much.

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