SL script for color using hue value
16 years ago
// The code below was generated by
// SCRATCH FOR SECOND LIFE (S4SL)
// alpha release October 19, 2007
//
// by Eric Rosenbaum (ericr@media.mit.edu)
// MIT Media Lab
// Lifelong Kindergarten group
//
// S4SL is a modified version of Scratch,
// a graphical programming language for kids
// see scratch.mit.edu
//
// take a color represented as a hue value between 1 and 100 and
// return an RGB vector representing the same color.
vector hueToRGB(float h)
{
float r; // red
float g; // green
float b; // blue
float s = 1; // saturation
float v = 1; // value
h *= 5; // sector 0 to 5
integer i = llFloor(h); // round down
float f = h - i; // factorial part of h
// technically we could simplify this with f = (h * 5) - llFloor(h * 5)
float p = v * ( 1 - s );
float q = v * ( 1 - s * f );
float t = v * ( 1 - s * ( 1 - f ) );
if (i == 0) { r = v; g = t; b = p; }
else if (i == 1) { r = q; g = v; b = p; }
else if (i == 2) { r = p; g = v; b = t; }
else if (i == 3) { r = p; g = q; b = v; }
else if (i == 4) { r = t; g = p; b = v; }
else { r = v; g = p; b = q; }
return <r,g,b>;
}
// setColor(float num)
// set the color of the object using a number between 1 and 100 representing a hue
float color;
setColor(float num)
{
color = (integer)num % 100;
llSetColor(hueToRGB(color / 100), ALL_SIDES);
llSetLinkColor(LINK_SET, hueToRGB(color / 100), ALL_SIDES);
}
vector touchedLoc;
default
{
touch(integer num_detected) // using touch instead of touch_start or touch_end will allow you to click-drag to the wanted color
{
integer i; for (i = 0; i < num_detected; i++) {
touchLoc = llDetectedTouchST(i); // xy location of the face touched
setColor(100/touchLoc.x ); // will only take the x value of the face touched
}
}
}
// SCRATCH FOR SECOND LIFE (S4SL)
// alpha release October 19, 2007
//
// by Eric Rosenbaum (ericr@media.mit.edu)
// MIT Media Lab
// Lifelong Kindergarten group
//
// S4SL is a modified version of Scratch,
// a graphical programming language for kids
// see scratch.mit.edu
//
// take a color represented as a hue value between 1 and 100 and
// return an RGB vector representing the same color.
vector hueToRGB(float h)
{
float r; // red
float g; // green
float b; // blue
float s = 1; // saturation
float v = 1; // value
h *= 5; // sector 0 to 5
integer i = llFloor(h); // round down
float f = h - i; // factorial part of h
// technically we could simplify this with f = (h * 5) - llFloor(h * 5)
float p = v * ( 1 - s );
float q = v * ( 1 - s * f );
float t = v * ( 1 - s * ( 1 - f ) );
if (i == 0) { r = v; g = t; b = p; }
else if (i == 1) { r = q; g = v; b = p; }
else if (i == 2) { r = p; g = v; b = t; }
else if (i == 3) { r = p; g = q; b = v; }
else if (i == 4) { r = t; g = p; b = v; }
else { r = v; g = p; b = q; }
return <r,g,b>;
}
// setColor(float num)
// set the color of the object using a number between 1 and 100 representing a hue
float color;
setColor(float num)
{
color = (integer)num % 100;
llSetColor(hueToRGB(color / 100), ALL_SIDES);
llSetLinkColor(LINK_SET, hueToRGB(color / 100), ALL_SIDES);
}
vector touchedLoc;
default
{
touch(integer num_detected) // using touch instead of touch_start or touch_end will allow you to click-drag to the wanted color
{
integer i; for (i = 0; i < num_detected; i++) {
touchLoc = llDetectedTouchST(i); // xy location of the face touched
setColor(100/touchLoc.x ); // will only take the x value of the face touched
}
}
}
FA+
