Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting: Change group color dynamicly

  • Scripting: Change group color dynamicly

    Posted by Ecko Locko on November 8, 2016 at 6:07 pm

    Hi,

    i am trying to create a Script that let me change a group color dynamicly.

    At this moment i get this code and cant make it works.

    If you see the code below there is a line with comments that i wish to use but doesnt work.

    My intention is that when i modify a slider the group change of background color and when i click in button, it creates a solid with that color (the code of create solid isnt there).

    Now the group only change color if i click on him but it only change with predefined colors…

    What im doing wrong? This is possible?

    Thanks a lot.

    win=new Window("palette","SolidColor",[0,0,210,210],{resizeable:true,borderless:true,minimizeButton:false,maximizeButton:false,resizeable:false,});

    panel_color=win.add("panel",[5,5,210,220]);

    group = win.add("panel",[5,5,205,40]);
    group.graphics.backgroundColor= group.graphics.newBrush(group.graphics.BrushType.SOLID_COLOR, [.1, .5, .7], 1);
    group.addEventListener ("click", function (m){handleMouseDown(m,group)});

    slider_h=panel_color.add("slider",[40,50,190,63],65,0,100);
    slider_s=panel_color.add("slider",[40,90,190,103],47.8494623655914,0,100);
    slider_l=panel_color.add("slider",[40,130,190,143],47.8494623655914,0,100);
    runBtn=panel_color.add("button",[12,170,142,192],"Generar");

    exitBtn=panel_color.add("button",[160,170,180,192],"X");
    hue_txt=win.add("statictext",[15,55,85,75] ,"Hue",{multiline:true});
    sat_txt=win.add("statictext",[15,95,85,115] ,"Sat",{multiline:true});
    lum_txt=win.add("statictext",[15,135,85,155] ,"Lum",{multiline:true});

    var h = parseFloat(slider_h.value / 100).toFixed(2);
    var s = parseFloat(slider_s.value / 100).toFixed(2);
    var l = parseFloat(slider_l.value / 100).toFixed(2);

    win.center();

    runBtn.onClick = function ()
    {
    getColorValues ();
    alert(h + " , " + s + " , " + l, "Hue, Saturation, Luminance");
    }

    exitBtn.onClick = function ()
    {
    win.close();
    }

    function getColorValues()
    {
    h = parseFloat(slider_h.value / 100).toFixed(2);
    s = parseFloat(slider_s.value / 100).toFixed(2);
    l = parseFloat(slider_l.value / 100).toFixed(2);

    }

    function handleMouseDown(ev,theButton){
    getColorValues();
    theButton.graphics.backgroundColor = theButton.graphics.newBrush(theButton.graphics.BrushType.SOLID_COLOR, [.5, .2, .3], 1); // Works Fine
    // theButton.graphics.backgroundColor = theButton.graphics.newBrush(theButton.graphics.BrushType.SOLID_COLOR, [h, s, l], 1); // Dont Work

    }

    win.center();
    win.show();

    Xavier Gomez replied 9 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Xavier Gomez

    November 8, 2016 at 9:55 pm

    You don’t seem to need the parseInt and toFixed(2) things.
    The input color should be an array of numbers [r, g, b,a] all in the range [0,1], not an array of strings.
    Something like this (i dont have a hslToRgb function at hand but you can find one very easily on the web):

    function getHSL(){return [slider_h.value / 100, slider_s.value / 100, slider_l.value / 100];}

    function handleMouseDown(ev,theButton){
    var hsl = getHSL();
    var rgb = hslToRgb(hsl);
    theButton.graphics.backgroundColor = theButton.graphics.newBrush(theButton.graphics.BrushType.SOLID_COLOR, rgb, 1);
    };

    Xavier

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