User:Tyken Hightower/TouchColoring
Jump to navigation
Jump to search
<lsl> float hue = 0.0; float luminosity = 1.0; float saturation = 1.0; float red = 1.0; float green = 1.0; float blue = 1.0;
update_color(vector touched) {
hue = touched.x; luminosity = touched.y; recolor();
}
update_saturation(vector touched) {
saturation = touched.x; recolor();
}
recolor() {
float q = 0.0; if (luminosity < 0.5) q = luminosity * (1.0 + saturation); else q = luminosity + saturation - (luminosity * saturation); float p = 2.0 * luminosity - q; red = hue + (1.0 / 3.0); green = hue; blue = hue - (1.0 / 3.0); if (red < 0.0) ++red; else if (red > 1.0) --red; if (green < 0.0) ++green; else if (green > 1.0) --green; if (blue < 0.0) ++blue; else if (blue > 1.0) --blue; if (red < (1.0 / 6.0)) red = p + ((q - p) * 6.0 * red); else if (red < 0.5) red = q; else if (red < (2.0 / 3.0)) red = p + ((q - p) * 6.0 * ((2.0 / 3.0) - red)); else red = p; if (green < (1.0 / 6.0)) green = p + ((q - p) * 6.0 * green); else if (green < 0.5) green = q; else if (green < (2.0 / 3.0)) green = p + ((q - p) * 6.0 * ((2.0 / 3.0) - green)); else green = p; if (blue < (1.0 / 6.0)) blue = p + ((q - p) * 6.0 * blue); else if (blue < 0.5) blue = q; else if (blue < (2.0 / 3.0)) blue = p + ((q - p) * 6.0 * ((2.0 / 3.0) - blue)); else blue = p; llSetLinkColor(3, <red, green, blue>, 0);
}
default {
touch(integer number) { // Only accept touch-enabled clients or touches on face 0. if (llDetectedTouchFace(0)) return; string link = llGetLinkName(llDetectedLinkNumber(0)); vector touched = llDetectedTouchST(0); //llOwnerSay((string)touched); if (link == "draw") draw(touched); else if (link == "color") update_color(touched); else if (link == "saturation") update_saturation(touched); }
} </lsl>