Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

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

Cow Forums : Adobe After Effects Expressions
cow
Peak value at Math.round with linear fall-off?
by Danny Parsons on May 10, 2008 at 7:27:03 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


Respond to this post     Return to posts index

cow
Re: Peak value at Math.round with linear fall-off?
by Darby Edelen on May 10, 2008 at 8:39:19 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

Respond to this post     Return to posts index

cow
Re: Peak value at Math.round with linear fall-off?
by Danny Parsons on May 11, 2008 at 12:46:44 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






Respond to this post     Return to posts index


cow
Re: Peak value at Math.round with linear fall-off?
by Dan Ebberts on May 11, 2008 at 6:19:21 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



Respond to this post     Return to posts index

cow
Re: Peak value at Math.round with linear fall-off?
by Danny Parsons on May 11, 2008 at 8:14:44 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: 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




Respond to this post     Return to posts index

cow
Re: Peak value at Math.round with linear fall-off?
by Dan Ebberts on May 11, 2008 at 11:04:05 pm

I guess that's a reasonable use of my site. Thanks for asking first though. :-)

Dan



Respond to this post     Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINEDVDsBOOKSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]