Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions converting one range of values into another range of values grrr… is this a clamping thing too?

  • converting one range of values into another range of values grrr… is this a clamping thing too?

    Posted by Jim Lefevre on March 19, 2012 at 10:56 am

    I think this is a clamping function thing (which I’m starting to get my head around) but it’s a little trickier in that there is a specific range I would like to clamp…

    I have a ‘SUN’ rotating and it effects a CC slant effect.

    The SUN rotation values that I need to read from are between

    0 x 270 – meaning a value of 270
    and
    1 x 90 – meaning a value of 450

    and the CC slant effect values that I need to return are between -100 and 100

    See attached

    So maybe clamp isn’t the thing I’m after as I’m actually wanting to convert one range ( 270 to 450) into another range (-100 to 100).

    Thank you so very much in advance and I feel the need to apologise about being on these forums so much these last few weeks – it’s really my first PROPER delve into these deep dark expression waters. And I’m loving it and really really learning!!!

    jim

    http://www.jimlefevre.com

    Jim Lefevre replied 14 years, 1 month ago 3 Members · 6 Replies
  • 6 Replies
  • Declan Smith

    March 19, 2012 at 12:11 pm

    Seems like you just need to change one scale to another, so I would tackle this by normalising the values by applying the code below to your slant effect value.

    Also, you would clamp your rotatation to your scale: So on the rotation put

    clamp(value,270,450)

    Hope this helps

    rotationCurrentValue=360; // This needs to be linked to your actual rotation value
    rotationMax=450;
    rotationMin=270;
    slantMin=-100;
    slantMax=100;
    rotationRange=450-270;
    slantRange=slantMax-slantMin;
    percentageFSD=(rotationCurrentValue-rotationMin)/rotationRange;

    newValue=(slantRange * percentageFSD) - slantMin;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS5.5/ FCS3 / Canon 7D / Canon XL2 / Reason / Cubase

    “it’s either binary or it’s not”

  • Jim Lefevre

    March 19, 2012 at 1:40 pm

    Declan,

    ahhhh… yes… ok, so that’s the thought-process-kick-in-cerebellum I needed.

    It’s not working yet but that feels entirely due to user error on this side.

    I think the main two things I might not have got clear are…

    i) When you say ‘clamp the rotation to your scale’ it’s probably really obvious but you mean the scale of the values here not the ‘scale’ of the layer. Actually even in writing that I know that it is. Anyhow, consider that baby ‘clamped’

    ii) When you say ‘rotationCurrentValue=360; // This needs to be linked to your actual rotation value’ … am I replacing the ‘rotationCurrentValue’ with a pick whip to the rotation value of the SUN or the bit that says ‘360’? It feels fairly obvious that it’s latter as that’s the only option that gives a variable driven by the SUN.

    I guess I only ask as the SLANT range (i.e. the returned results after the expression) that I’m getting when I do the latter is between 100 and 300 which is promising as it’s definitely giving me a 200 value range.

    I’ve put in

    (newValue-200)*-1

    at the end and that’s pretty much cracked it but I was wondering if I’d done something wrong before that point…

    Brilliant though, really brilliant, and also so very useful to get the idea of interpolating one range into another too..

    Oh and love the Llangollen Narrow boat film. Funnily enough was going to do the saw stretch last year with my Parents in Law but ended up doing one south of the Chippendale museum, mostly as we have a 2 year old daughter and my Parents in Law had awful visions of small children and high aqueducts!

    http://www.jimlefevre.com

  • Declan Smith

    March 19, 2012 at 2:51 pm

    Hi

    i) Yes, I mean add the clamp(value,270,450) to your rotation value itself (alt/option click on the rotation and add that there)

    ii) Yes, select the numbers 360 then pickwhip to the rotation value so that it would read something like (assuming the layer is called “Sun”):

    rotationCurrentValue=thisComp.layer(“Sun”).transform.rotation

    It doesn’t help when there is an error in the script 🙁 Please see below. The last line should have been a + not –

    rotationCurrentValue=thisComp.layer("Sun").transform.rotation; // This needs to be linked to your actual rotation
    rotationMax=450;
    rotationMin=270;
    slantMin=-100;
    slantMax=100;
    rotationRange=450-270;
    slantRange=slantMax-slantMin;
    percentageFSD=(rotationCurrentValue-rotationMin)/rotationRange;

    newValue=(slantRange * percentageFSD) + slantMin;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS5.5/ FCS3 / Canon 7D / Canon XL2 / Reason / Cubase

    “it’s either binary or it’s not”

  • Dan Ebberts

    March 19, 2012 at 3:44 pm

    I think all you should need would be something like this:

    sunRotation = thisComp.layer(“sun”).transform.rotation;
    linear(sunRotation,270,450,-100,100)

    Dan

  • Declan Smith

    March 19, 2012 at 3:54 pm

    Nice! Much better way of doing it.

    Declan Smith
    https://www.madpanic.tv
    After Effects CS5.5/ FCS3 / Canon 7D / Canon XL2 / Reason / Cubase

    “it’s either binary or it’s not”

  • Jim Lefevre

    March 22, 2012 at 12:12 pm

    Brilliant!

    Thanks Declan and as always, thanks Dan!

    That’s incredibly stripped down and tight and the second time I’ve come across that ‘linear’ thing. I’m going to go back to the last time I used it and try and extrapolate a bit more meaning from it and see if I can hold it in my brain!!!

    jim

    http://www.jimlefevre.com

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