Jump to content

Multi Frequency Color Picker


Usive
 Share

You are about to reply to a thread that has been inactive for 4307 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have this script for a color picker, and I want to change it so that instead of immediately sending commands to the pre-coded frequency, it lets you pick an frequency/integer (from a menu I am thinking) that you would like to use. Or maybe even which frequencies out of multiple you'd like to use. and THEN sends the commands to the frequencies you have chosen.

 I believe line 92 is about where the change needs to be made.

Here is the script in question.

 

//              HSL Color Picker (1-prim)
//                  by Bjorn Nordlicht
//
//                  COLOR PICKER SCRIPT
//
//
// This is a 1-prim HSL color picker, it works much like
// the built-in color picker in SecondLife edit window.
//
// HSL (hue-saturation-light) is another way of describing
// colors apart from RGB (red-green-blue), which is what
// LSL functions such as llSetColor require.
//
// Usage:
//  1. Drop TRANSFORM and this script into desired prim.
//  2. Touch HS plane to select your color
//  3. Touch L axis to select lightness/darkness
//  4. The picker will say color on CMD_CH
//  5. Modify script and prim as needed
//

integer HS_PLANE_FACE = 2;
integer L_AXIS_FACE = 4;
integer CMD_CH  = -1024;
vector HSL = <0.0, 0.0, 0.5>;


//Set new color and (optionally) preview
new_hsl_color(vector color)
{
    //llSetColor(hsl_2_rgb(<color.x, color.y, 0.5>), L_AXIS_FACE);
    llSay(CMD_CH, (string)hsl_2_rgb(color));
    llSleep(0.1);
}

//Wrap value to between 0 and 1
float scale_f(float f)
{
    if (f < 0.0)
    {
        f += 1.0;
    }
    else if(f > 1.0)
    {
        f -= 1.0;
    }
   
    return f;
}

//Calculate RGB from (t, p, q)
float rgb_color(float c, float p, float q)
{
    if(c < 0.166667)
    {
        return p+(q-p)*6*c;
    }
    else if(c >= 0.166667 && c < 0.5)
    {
        return q;
    }
    else if(c >= 0.5 && c < 0.666667)
    {
        return p+(q-p)*6*(0.666667 - c);
    }
    else
    {
        return p;
    }
}

//Convert HSL color to RGB color
vector hsl_2_rgb(vector color)
{
    float p;
    float q;
    vector t = <scale_f(color.x + 0.333333), scale_f(color.x), scale_f(color.x - 0.333333)>;
   
    if (HSL.z < 0.5)
    {
        q = color.z * (1 + color.y);
    }
    else
    {
        q = color.z + color.y - (color.z * color.y);
    }
   
    p = 2*color.z - q;
   
    return <rgb_color(t.x, p, q), rgb_color(t.y, p, q), rgb_color(t.z, p, q)>;
}

default
{
    state_entry()
    {   //Initial color
        //new_hsl_color(HSL);
    }

    touch_start(integer n)
    {
        integer face = llDetectedTouchFace(0);
        if(face == HS_PLANE_FACE)
        {   //HS plane
            vector v = llDetectedTouchST(0);
            HSL = <v.y, 1.0 - v.x, HSL.z>;
           
            new_hsl_color(HSL);
        }
        else if(face == L_AXIS_FACE)
        {   //L axis
            vector v = llDetectedTouchST(0);
            HSL = <HSL.x, HSL.y, v.y>;
           
            new_hsl_color(HSL);
        }
        else if(face == -1)
        {   //TOUCH_INVALID_FACE ~ outdated viewer
            llInstantMessage(llDetectedKey(0), "Please update your viewer to use this color picker :P");
        }
    }

    touch(integer n)
    {
        integer face = llDetectedTouchFace(0);
        if(face == HS_PLANE_FACE)
        {   //HS plane
            vector v = llDetectedTouchST(0);
            HSL = <v.y, 1.0 - v.x, HSL.z>;
           
            new_hsl_color(HSL);
        }
        else if(face == L_AXIS_FACE)
        {   //L axis
            vector v = llDetectedTouchST(0);
            HSL = <HSL.x, HSL.y, v.x>;
           
            new_hsl_color(HSL);
        }
    }
}

  • Like 1
Link to comment
Share on other sites

maybe we can incorperate that script I showed you into it.. the menu script..  just tell this one to use a scrpt after you select the color .. telling it which prim you want to change.. .. we put the receiver in each of the prims and have it listen to a specific channel. .. we have this script .. with the menu... on the menu we put which channel to send it to..

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4307 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...