• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

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?

TOPICS
Expressions

Views

179

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2021 Jul 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

clamp values.gif

Plug those variables into your expre

...

Votes

Translate

Translate
LEGEND ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

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

clamp values.gif

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. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 11, 2021 Jul 11, 2021

Copy link to clipboard

Copied

LATEST

Thank you very much!

 

This is exactly what I meant!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines