Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Add 10% brightness to shape layer fill HSB

  • Add 10% brightness to shape layer fill HSB

    Posted by John Cuevas
    on January 3, 2024 at 7:41 pm

    I’m trying to use the fill color from one shape layer, input it into another shape layers fill layer, with a 10% boost to the brightness of the HSB. I been working with ChatGPT, but I keep getting the same input error on line 1. “object of type found where a Number, Array, or Property is needed”

    Any ideas?

    // Assuming “color” is the input color property

    inputColor = color; // Replace “color” with your actual color property

    // Convert color to RGB

    rgbColor = [inputColor[0]/255, inputColor[1]/255, inputColor[2]/255];

    // Extract HSB components

    h = rgbToHsl(rgbColor)[0];

    s = rgbToHsl(rgbColor)[1];

    b = rgbToHsl(rgbColor)[2];

    // Calculate new brightness with a 10% increase

    brightnessIncrease = 0.10;

    newBrightness = clamp(brightnessIncrease + b, 0, 1);

    // Convert back to RGB

    newColor = hslToRgb([h, s, newBrightness]);

    // Return the new color

    newColor

    // Function to convert RGB to HSL

    function rgbToHsl(rgb) {

    var r = rgb[0];

    var g = rgb[1];

    var b = rgb[2];

    var max = Math.max(r, g, b), min = Math.min(r, g, b);

    var h, s, l = (max + min) / 2;

    if (max == min) {

    h = s = 0; // achromatic

    } else {

    var d = max – min;

    s = l > 0.5 ? d / (2 – max – min) : d / (max + min);

    switch (max) {

    case r: h = (g – b) / d + (g < b ? 6 : 0); break;

    case g: h = (b – r) / d + 2; break;

    case b: h = (r – g) / d + 4; break;

    }

    h /= 6;

    }

    return [h, s, l];

    }

    // Function to convert HSL to RGB

    function hslToRgb(hsl) {

    var h = hsl[0];

    var s = hsl[1];

    var l = hsl[2];

    var r, g, b;

    if (s == 0) {

    r = g = b = l; // achromatic

    } else {

    function hue2rgb(p, q, t) {

    if (t < 0) t += 1;

    if (t > 1) t -= 1;

    if (t < 1 / 6) return p + (q – p) * 6 * t;

    if (t < 1 / 2) return q;

    if (t < 2 / 3) return p + (q – p) * (2 / 3 – t) * 6;

    return p;

    }

    var q = l < 0.5 ? l * (1 + s) : l + s – l * s;

    var p = 2 * l – q;

    r = hue2rgb(p, q, h + 1 / 3);

    g = hue2rgb(p, q, h);

    b = hue2rgb(p, q, h – 1 / 3);

    }

    return [r * 255, g * 255, b * 255];

    }

    John Cuevas
    replied 11 months ago
    2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 3, 2024 at 7:58 pm

    Maybe like this:

    c = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Fill 1").color;
    hsl = rgbToHsl(c);
    newL = Math.min(hsl[2]*1.1,1);
    hslToRgb([hsl[0],hsl[1],newL,hsl[3]])
  • John Cuevas

    January 3, 2024 at 8:03 pm

    Dan you are the best!!!

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