Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Peak value at Math.round with linear fall-off?

  • Peak value at Math.round with linear fall-off?

    Posted by Danny Parsons on May 10, 2008 at 7:27 pm

    Hi there…

    I know that I’m missing something terribly simple here, but I just can’t seem to find what I’m looking for…

    As with a post I made around a week ago, I’ll present my query as a simplified hypothetical … It’s all part of the same project; itself a fun but otherwise pointless exercise I’ve devised in order to improve my proficiency with expressions…

    Let’s say that I want to link a layer’s opacity to a slider, having it reach 100% whenever the slider’s value represents a whole number, then to ramp down linearly to 50% between integers.

    Thanks in advance,

    DP

    Dan Ebberts replied 18 years ago 3 Members · 5 Replies
  • 5 Replies
  • Darby Edelen

    May 10, 2008 at 8:39 pm

    [Danny Parsons] “Let’s say that I want to link a layer’s opacity to a slider, having it reach 100% whenever the slider’s value represents a whole number, then to ramp down linearly to 50% between integers.”

    Try this:


    x = effect("Slider Control")("Slider");
    x = x % 1;
    if(x < .5) x = linear(x, 0, .5, 1, .5); linear(x, .5, 1, 50, 100);

    There may be a more elegant way to do that, but I think it should work.

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

  • Danny Parsons

    May 11, 2008 at 12:46 pm

    Thanks Darby,

    Your expression is working fine for what I’m currently doing. I am, however, having a little trouble when I play around with adapting it… Let’s say I wanted the opacity to peak whenever the slider hits a multiple of ten, instead of any whole number, with the same linear fall-off… I’ve tried a few things to no avail, and I think the main problem is that I don’t quite understand what the second line of the expression is actually doing (“x = x % 1”)… I’d thought that the “%” operator meant “return the remainder of x/y”, but in this case y = 1 – so I’m having trouble understanding where any remainder (or anything else meaningful, for that matter!) is actually coming from…

    Thanks again for your initial response; any further elucidation would be great though…

    Cheers,

    DP

  • Dan Ebberts

    May 11, 2008 at 6:19 pm

    Here’s a more general version of Darby’s expression – just change the vairable “multiple” to set the spacing between the peak values.

    x = effect(“Slider Control”)(“Slider”);
    multiple = 10;
    x = x % multiple;
    if(x < multiple/2) x = linear(x, 0, multiple/2, 100, 50); linear(x, multiple/2, multiple, 50, 100); FYI, %1 in the previous version just gives you the fractional part of the number. So, for example, 1.3 % 1 is .3 which is what the expression needed when the peaks occured on every integer. Dan

  • Danny Parsons

    May 11, 2008 at 8:14 pm

    Hi Dan,

    Thanks – the whole “% 1” thing makes sense to me now, and I’m sure the new, generic expression will come in handy again sometime…

    Whilst I have you on the line, I wanted to ask before doing so, whether you’d have any objections to my copying your site to disk (using something like this free application: http://www.httrack.com) for personal use. I like to keep my work-box offline, and so it would be great to be able to follow your examples, paste your code, etc. – and still have all of the site’s links interact properly, as though I were online…

    Thanks again,

    DP

  • Dan Ebberts

    May 11, 2008 at 11:04 pm

    I guess that’s a reasonable use of my site. Thanks for asking first though. 🙂

    Dan

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