Skip to main content
Bram Hoekstra
Inspiring
July 11, 2021
Answered

How to auto calculate a number when a slider is in a certain range?

  • July 11, 2021
  • 2 replies
  • 389 views

I'm curious if there's is a solution to the following:

 

var horizontal = comp("Render").layer("Controller").effect("B-films Credits Builder")("Horizontal Position");
var vertical = comp("Render").layer("Controller").effect("B-films Credits Builder")("Vertical Position");
var depth = comp("Render").layer("Controller").effect("B-films Credits Builder")("Depth Position");
[horizontal, 1920 - 420 - vertical, -depth];

 

The bold text has to be automatically calculated when the vertical slider is between 0 and 540.

If the vertical slider is at 540 it should be 420, when the vertical slider is at 0 it should be 0 and between those value it should calculate the value automatically.

 

Is there any way to do this?

This topic has been closed for replies.
Correct answer Rick Gerard

You just need to declare some variables. Here's the code on a text layer and the resulting values:

vertical = effect("Slider 1")("Slider").value.toFixed(1);
vertical_Clamp = clamp(vertical, 0, 540).toFixed(1);
vertical_Ofst = linear(vertical_Clamp, 0, 540, 0, 420).toFixed(1);
// the following code displays the values for the variables
"Vertical Slider:  " + vertical  + "\r" + 
"Vertical Clamp: " + vertical_Clamp + "\r" +
"Vertical Offset: " + vertical_Ofst

Plug those variables into your expression and it should work. I added clamp(1) to the end of each variable to clean up the text display. You can delete it unless you want pixel-level rounding. 

 

2 replies

Rick GerardCommunity ExpertCorrect answer
Community Expert
July 11, 2021

You just need to declare some variables. Here's the code on a text layer and the resulting values:

vertical = effect("Slider 1")("Slider").value.toFixed(1);
vertical_Clamp = clamp(vertical, 0, 540).toFixed(1);
vertical_Ofst = linear(vertical_Clamp, 0, 540, 0, 420).toFixed(1);
// the following code displays the values for the variables
"Vertical Slider:  " + vertical  + "\r" + 
"Vertical Clamp: " + vertical_Clamp + "\r" +
"Vertical Offset: " + vertical_Ofst

Plug those variables into your expression and it should work. I added clamp(1) to the end of each variable to clean up the text display. You can delete it unless you want pixel-level rounding. 

 

Bram Hoekstra
Inspiring
July 11, 2021

Thank you very much!

 

This is exactly what I meant!

Mylenium
Legend
July 11, 2021

If you know the values it's as imple as using a linear() interpolator to derive the inbetween values:

 

linear(vertical, 540,0,420,0);

 

Mylenium

Bram Hoekstra
Inspiring
July 11, 2021

It sorta works, it sorta doesn't.

I need the slider to keep it's original values.

I only need the offset between 1920 and the slider to be recalculated.