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

Expressions mix slider for blending between RGB white and input color

Community Expert ,
Mar 14, 2025 Mar 14, 2025

I ain't the smartest when it comes to math and code. I have a setup that controls a color with two operators. A color picker and a slider that multiplies. Current code:

// Get params
baseColor = effect("Linear Gain")("Color");
gain = effect("Linear Gain")("Gain");

// Multiply the color by the gain value
[baseColor[0] * gain, baseColor[1] * gain, baseColor[2] * gain, baseColor[3]];

I'd like to add an additional slider that can go from 0-100(%) that can control the amount of change from 0% which should result in [1,1,1,1float] ie. 'white' to the specified color*gain result being 100%.

 

Would love to have some assistance with this.

TOPICS
Expressions , Scripting
48
Translate
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 , Mar 16, 2025 Mar 16, 2025

Found a solution through gpt. This is the new code should it help anyone.

// Get params
baseColor = effect("Linear Gain")("Color");
gain = effect("Linear Gain")("Gain");
mixPercent = effect("Linear Gain")("Mix");

// Normalize the mix percentage (from slider) to a 0-1 range
mix = mixPercent / 100;

// Calculate the interpolated color
interpolatedColor = [
    baseColor[0] * gain * mix + (1 - mix),
    baseColor[1] * gain * mix + (1 - mix),
    baseColor[2] * gain * mix + (1 - mix),
    baseColor
...
Translate
Community Expert ,
Mar 16, 2025 Mar 16, 2025
LATEST

Found a solution through gpt. This is the new code should it help anyone.

// Get params
baseColor = effect("Linear Gain")("Color");
gain = effect("Linear Gain")("Gain");
mixPercent = effect("Linear Gain")("Mix");

// Normalize the mix percentage (from slider) to a 0-1 range
mix = mixPercent / 100;

// Calculate the interpolated color
interpolatedColor = [
    baseColor[0] * gain * mix + (1 - mix),
    baseColor[1] * gain * mix + (1 - mix),
    baseColor[2] * gain * mix + (1 - mix),
    baseColor[3] // Assuming we want the original alpha value
];

// Return the interpolated color
interpolatedColor;

 

Translate
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