|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
02-17-2007 19:00
hey, simple question. ive used the setcolor to chnage colors on alot of items in the past, however i just made something that is more complex color and texture wise, and i need the option of changing the Hue, Sat, and Lum. i dont see a script in the wiki for that and havent found it in the forumns. is it possible?
and if so whats the code r link to it? thanks again
|
|
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
|
02-17-2007 23:34
There are number of algorythms for doing this at http://www.cs.rit.edu/~ncs/color/t_convert.html and other places within reach of Google for the terms "rgb hsv convert" and "colorspace convert", but I don't think anyone's done it for LSL yet, at least nothing pops out from the hour I spent once going through all the contributions to the scripting library forum. It doesn't look like the algorythms are all that hard to implement so if you're minimally competent with LSL you could easily roll your own process.
|
|
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
|
02-18-2007 00:59
The above link describes HSV conversion, not HSL. I've written the following functions (first one for HSL, second one for HSV): // Converts HSL colors to RGB // Input must be a vector in the form <H, S, L>. // Output is an <R, G, B> vector suitable for llSetColor(). // Valid ranges: 0 <= H < 360 // 0 <= S <= 1.0 // 0 <= L <= 1.0 vector HSLtoRGB(vector hsl) { float H = hsl.x; float S = hsl.y; float L = hsl.z; if (S == 0.0) return <L, L, L>; float Q = 0; if (L < 0.5) Q = L*(1.0+S); else Q = L+S-(L*S); float P = 2.0 * L - Q; float Hk = H/360.0; float r = CalcHSLRGB(Hk + (1.0/3.0), P, Q); float g = CalcHSLRGB(Hk, P, Q); float b = CalcHSLRGB(Hk - (1.0/3.0), P, Q); return <r, g, b>; }
// This function is needed by HSLtoRGB(). float CalcHSLRGB(float T, float P, float Q) { if (T < 0.0) T += 1.0; else if (T > 1.0) T -= 1.0; float c = 0; if (T < (1.0/6.0)) c = P + ((Q-P)*6.0*T); else if (T < (0.5)) c = Q; else if (T < (2.0/3.0)) c = P + ((Q-P)*((2.0/3.0)-T)*6.0); else c = P; return c; }
// Converts HSV colors to RGB. // Input must be a vector in the form <H, S, V>. // Output is an <R, G, B> vector suitable for llSetColor(). // Valid ranges: 0 <= H < 360 // 0 <= S <= 1.0 // 0 <= V <= 1.0 vector HSVtoRGB(vector hsv) { float H = hsv.x; float S = hsv.y; float V = hsv.z; float Hi = llFloor(H/60) % 6; float f = (H/60) - Hi; float p = V*(1-S); float q = V*(1-f*S); float t = V*(1-(1-f)*S); vector rgb = <0, 0, 0>; if (Hi == 0) rgb = <V, t, p>; else if (Hi == 1) rgb = <q, V, p>; else if (Hi == 2) rgb = <p, V, t>; else if (Hi == 3) rgb = <p, q, V>; else if (Hi == 4) rgb = <t, p, V>; else if (Hi == 5) rgb = <V, p, q>;
return rgb; }
Example usage: vector hsl = <120, 1, 0.25>; vector rgb = HSLtoRGB(hsl); llSetColor(rgb, ALL_SIDES);
-peekay
|
|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
thanks
02-18-2007 02:24
thanks, soon as i get home from work ill try those out 
|