Skip to main content
Shebbe
Community Expert
Community Expert
March 14, 2025
Answered

Expressions mix slider for blending between RGB white and input color

  • March 14, 2025
  • 1 reply
  • 173 views

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.

Correct answer Shebbe

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;

 

1 reply

Shebbe
Community Expert
ShebbeCommunity ExpertAuthorCorrect answer
Community Expert
March 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[3] // Assuming we want the original alpha value
];

// Return the interpolated color
interpolatedColor;