Jump to content

Script command to change Hue?


Mistychu
 Share

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

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

Recommended Posts

This page from the wiki should help you: http://wiki.secondlife.com/wiki/LlSetPrimitiveParams

For color, you have to convert the color to a vector.  For instance (255,0,0)  must be expressed as <1,0,0>.  Here is more information about that: http://wiki.secondlife.com/wiki/Category:LSL_Color.  If the color you want is not on that list, you can also rez a prim and custom color it using the color picker then drop a script into it to get the vector.  This page has the code you need to do that http://wiki.secondlife.com/wiki/LlGetColor

Link to comment
Share on other sites

This is how far I got; 

 

 

Below is entire script, trying to get it to -h value every time HslToRgb is called and script would repeat itself.

 

I don't know how to properly call these within confines of llSetColor


llSetColor(<HslToRgb(RgbToHsl(llGetColor))>,1);



float repeats = 0;


vector RgbToHsl(vector rgb)

{

float r = rgb.x;

float g = rgb.y;

float b = rgb.z;

float h;

float s;

float l;

float max;

float min;


// Looking for the max value among r, g and b

if (r > g && r > b) max= r;

else if (g > b) max = g;

else max = b;


// Looking for the min value among r, g and b

if (r < g && r < b) min = r;

else if (g < b) min = g;

else min = b;


l = (max + min) / 2.0;


if (max == min)

{

h = 0.0;

s = 0.0;

}

else

{

float d = max - min;


if (l > 0.5) s = d / (2.0 - max - min);

else s = d / (max + min);


if (max == r) {

if (g < b) h = (g - b) / d + 6.0;

else h = (g - b) / d;

}

else if (max == g)

h = (b - r) / d + 2.0;

else

h = (r - g) / d + 4.0;

h /= 6.0;

}

h = h - 0.003;

return <h, s, l>;

}

vector HslToRgb(vector hsl)

{

float r;

float g;

float b;


if (hsl.y == 0.0) // If saturation is 0 the image is monochrome

r = g = b = hsl.z;

else

{

float q;

if (hsl.z < 0.5)

q = hsl.z * (1.0 + hsl.y);

else

q = hsl.z + hsl.y - hsl.z * hsl.y;


float p = 2.0 * hsl.z - q;


r = HueToRgb(p, q, hsl.x + 1.0 / 3.0);

g = HueToRgb(p, q, hsl.x);

b = HueToRgb(p, q, hsl.x - 1.0 / 3.0);

}

return <®, (g), (b)>;

}


float HueToRgb(float p, float q, float t)

{

if (t < 0.0) t += 1.0;

if (t > 1.0) t -= 1.0;

if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;

if (t < 1.0 / 2.0) return q;

if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;

return p;

}

default

{

on_rez(integer start_param)

{

llSetColor(<1,0,0>,1); //Set Color Red on Rez

// Restarts the script every time the object is rezzed

llResetScript();

}

state_entry()

{

llSetTextureAnim(ANIM_ON | SMOOTH | LOOP,1,0,0,0, 0,0);

llSetTimerEvent(3.3);

}

timer() {

if (repeats == 3 || repeats >= 3) {

float texture = llFrand(3);

if (texture <= 1.001) {

}

else if (texture <= 2.001 && texture >= 1) {

}

else if (texture >= 2) {

}

repeats = 0;

}

else {

repeats += 1;

}


llSetColor(<HslToRgb(RgbToHsl(llGetColor))>,1);

llSleep(0.02);

}


}




Link to comment
Share on other sites

Updated the main call, I saw I misused llGetColor without the proper face call.

 

llSetColor(<HslToRgb(RgbToHsl(llGetColor(1)))>,1);

 

Get Color Gets a Color Vector; 

 

RgbToHsl Takes a Rgb Vector and Converts it to a Hsl

 

Then HslToRgb converts the Hsl back to a Rgb after h = h - 0.003 (or a value I haven't decided yet tweakable)

 

And Should submit it to in the end to llsetcolor which sets it to a face

Link to comment
Share on other sites

Alright finished the script and got it working correctly  Not user friendly at all lol, but here's what I'm having trouble with now with my new primary call.

 

I'm trying to get one vector to store data for a the rgb call so I can use that vector on the iteration to change multiple face colors at once.

 

 

Specifically error comes up here;

Syntax error on the rgbFinal call.

rgbFinal = HslToRgb(RgbToHsl(llGetColor(face1));
llSetColor(rbgFinal,face1);
llSetColor(rbgFinal,face2);
llSetColor(rbgFinal,face3);
llSetColor(rbgFinal,face4);
llSetColor(rbgFinal,face5);

 

 


float repeats = 0;

float speed = 0.1;

float face1 = 0;

float face2 = 1;

float face3 = 2;

float face4 = 3;

float face5 = 4;

vector rbgFinal;

vector RgbToHsl(vector rgb)

{

float r = rgb.x;

float g = rgb.y;

float b = rgb.z;

float h;

float s;

float l;

float max;

float min;


// Looking for the max value among r, g and b

if (r > g && r > b) max= r;

else if (g > b) max = g;

else max = b;


// Looking for the min value among r, g and b

if (r < g && r < b) min = r;

else if (g < b) min = g;

else min = b;


l = (max + min) / 2.0;


if (max == min)

{

h = 0.0;

s = 0.0;

}

else

{

float d = max - min;


if (l > 0.5) s = d / (2.0 - max - min);

else s = d / (max + min);


if (max == r) {

if (g < b) h = (g - b) / d + 6.0;

else h = (g - b) / d;

}

else if (max == g)

h = (b - r) / d + 2.0;

else

h = (r - g) / d + 4.0;

h /= 6.0;

}

h = h - 0.002777776;


if (h <= 0.003){ h = 0; return <h, s, l>;}

else {

return <h, s, l>;}

}

vector HslToRgb(vector hsl)

{

float r;

float g;

float b;


if (hsl.y == 0.0) // If saturation is 0 the image is monochrome

r = g = b = hsl.z;

else

{

float q;

if (hsl.z < 0.5)

q = hsl.z * (1.0 + hsl.y);

else

q = hsl.z + hsl.y - hsl.z * hsl.y;


float p = 2.0 * hsl.z - q;


r = HueToRgb(p, q, hsl.x + 1.0 / 3.0);

g = HueToRgb(p, q, hsl.x);

b = HueToRgb(p, q, hsl.x - 1.0 / 3.0);

}

return <®, (g), (b)>;

}


float HueToRgb(float p, float q, float t)

{

if (t < 0.0) t += 1.0;

if (t > 1.0) t -= 1.0;

if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;

if (t < 1.0 / 2.0) return q;

if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;

return p;

}


default

{

state_entry()

{

llSetTextureAnim(ANIM_ON | SMOOTH | LOOP,1,0,0,0, 0,0);

llSetTimerEvent(speed);

}

timer() {

if (repeats == 3 || repeats >= 3) {

float texture = llFrand(3);

if (texture <= 1.001) {

}

else if (texture <= 2.001 && texture >= 1) {

}

else if (texture >= 2) {

}

repeats = 0;

}

else {

repeats += 1;

}

rgbFinal = HslToRgb(RgbToHsl(llGetColor(face1));

llSetColor(rbgFinal,face1);

llSetColor(rbgFinal,face2);

llSetColor(rbgFinal,face3);

llSetColor(rbgFinal,face4);

llSetColor(rbgFinal,face5);

}

}


 

Link to comment
Share on other sites

small change to the end....? rbg .. not rgb...and set faces to integer :)

~ also added missing bracket

 

rbgFinal = HslToRgb(RgbToHsl(llGetColor( (integer)face1)) );
llSetColor(rbgFinal,(integer)face1);
llSetColor(rbgFinal,(integer)face2);
llSetColor(rbgFinal,(integer)face3);
llSetColor(rbgFinal,(integer)face4);
llSetColor(rbgFinal,(integer)face5);

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3290 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...