OsSetPenColor

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Example added)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{osslfunc|
+
{{osslfunc
threat_level = None
+
|threat_level=ignored
|
+
|permissions=true
function_syntax = <source lang="lsl">
+
|delay=0
LSL: String osSetPenColor( String drawList, string color )  
+
|additional_info=This function was added in 0.7.2-post-fixes; Variants with vector and alpha arguments added in 0.9.3.0
C#: String osSetPenColor( String drawList, string color )  
+
|function_syntax=string osSetPenColor(string drawList, string color)<br>
</source>
+
string osSetPenColor(string drawList, vector color)<br>
|
+
string osSetPenColor(string drawList, vector color, float alpha)
ossl_example = <source lang="lsl">
+
|ossl_example=<source lang="lsl">
 
// Example of osSetPenColor
 
// Example of osSetPenColor
 
+
 
string hexDigits = "0123456789abcdef";
 
string hexDigits = "0123456789abcdef";
list colorNames = [ "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque",
+
list colorNames = [
"Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
+
    "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque",
"CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
+
    "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
"Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGrey",
+
    "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
"DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange",
+
    "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGrey",
"DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue",
+
    "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange",
"DarkSlateGrey", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue",
+
    "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue",
"DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia",
+
    "DarkSlateGrey", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue",
"Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Grey", "Green", "GreenYellow",
+
    "DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia",
"Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender",
+
    "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Grey", "Green", "GreenYellow",
"LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral",
+
    "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender",
"LightCyan", "LightGoldenrodYellow", "LightGreen", "LightGrey", "LightPink",
+
    "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral",
"LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGrey",
+
    "LightCyan", "LightGoldenrodYellow", "LightGreen", "LightGrey", "LightPink",
"LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
+
    "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGrey",
"Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple",
+
    "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
"MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise",
+
    "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple",
"MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin",
+
    "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise",
"NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed",
+
    "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin",
"Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
+
    "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed",
"PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple",
+
    "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
"Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown",
+
    "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple",
"SeaGreen", "Seashell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGrey",
+
    "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown",
"Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato",
+
    "SeaGreen", "Seashell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGrey",
"Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen" ];
+
    "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato",
 +
    "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen"
 +
];
  
 
default
 
default
 
{
 
{
state_entry()
+
    state_entry()
{
+
    {
string CommandList = ""; // Storage for our drawing commands
+
        // Storage for our drawing commands
integer i;
+
        string CommandList = "";
 +
        integer i;
 +
        // Set the pen width to 1 pixel
 +
        CommandList = osSetPenSize(CommandList, 1);
  
CommandList = osSetPenSize( CommandList, 1 ); // Set the pen width to 1 pixel
+
        // draw each named color as a single horizontal line
 +
        for (i = 0; i < 140; ++i)
 +
        {
 +
            // Set the pen to the next color name in our list
 +
            CommandList = osSetPenColor(CommandList, llList2String( colorNames, i));
 +
            // Now draw a line in that color
 +
            CommandList = osDrawLine(CommandList, 0, i, 255, i);
 +
        }
  
for (i = 0; i < 140; ++i) // draw each named color as a single horizontal line
+
        // Now let's fill up the remainder with lines of random colors, leaving a gap of 20 lines.
{
+
        for (i = 161; i < 256; ++i)
// Set the pen to the next color name in our list
+
        {
CommandList = osSetPenColor( CommandList, llList2String( colorNames, i ));
+
            // give it an opaque alpha
// Now draw a line in that color
+
            string thisColor = "ff";
CommandList = osDrawLine( CommandList, 0, i, 255, i );
+
            integer j;
}
+
  
// Now let's fill up the remainder with lines of random colors, leaving a gap of 20 lines.
+
            // then choose six random hex digits for the color
for (i = 161; i < 256; ++i)
+
            for (j = 0; j < 6; ++j)
{
+
            {
string thisColor = "ff"; // give it an opaque alpha
+
                integer k = (integer)llFrand(16.0);
integer j;
+
                thisColor += llGetSubString(hexDigits, k, k);
for (j = 0; j < 6; ++j) // then choose six random hex digits for the color
+
            }
{
+
            CommandList = osSetPenColor(CommandList, thisColor);
integer k = (integer) llFrand( 16.0 );
+
            CommandList = osDrawLine(CommandList, 0, i, 255, i);
thisColor += llGetSubString( hexDigits, k, k );
+
        }
}
+
        // Now generate the texture and apply it to the prim
CommandList = osSetPenColor( CommandList, thisColor );
+
        osSetDynamicTextureData("", "vector", CommandList, "width:256,height:256", 0);
CommandList = osDrawLine( CommandList, 0, i, 255, i );
+
    }
}
+
// Now generate the texture and apply it to the prim
+
osSetDynamicTextureData( "", "vector", CommandList, "width:256,height:256", 0 );
+
}
+
 
}
 
}
 
</source>  
 
</source>  
|
 
additional_info = Appends a [[Drawing commands#PenColour|PenColor]] drawing command to the string provided in '''drawList''' and returns the result.
 
  
This sets the pen's drawing color to either the specified [http://msdn.microsoft.com/en-us/library/aa358802.aspx named .NET color] or to a 32-bit color value (formatted as eight hexadecimal digits in the format aarrggbb, representing the eight-bit alpha, red, green and blue channels).  
+
<source lang="lsl">
 +
// Generating a calibrated color checker
 +
 +
integer SIZE    = 512;
 +
integer NROWS  = 4;
 +
integer NCOLS  = 6;
 +
integer MARGIN  = 6;
 +
 +
// Color definitions in xyY space
 +
// https://home.cis.rit.edu/~cnspci/references/mccamy1976.pdf
 +
 
 +
list xyYColors = [
 +
    <0.400, 0.350, 10.1>,
 +
    <0.377, 0.345, 35.8>,
 +
    <0.247, 0.251, 19.3>,
 +
    <0.337, 0.422, 13.3>,
 +
    <0.265, 0.240, 24.3>,
 +
    <0.261, 0.343, 43.1>,
 +
    <0.506, 0.407, 30.1>,
 +
    <0.211, 0.175, 12.0>,
 +
    <0.453, 0.306, 19.8>,
 +
    <0.285, 0.202, 6.60>,
 +
    <0.380, 0.489, 44.3>,
 +
    <0.473, 0.438, 43.1>,
 +
    <0.187, 0.129, 06.1>,
 +
    <0.305, 0.478, 23.4>,
 +
    <0.539, 0.313, 12.0>,
 +
    <0.448, 0.470, 59.1>,
 +
    <0.364, 0.233, 19.8>,
 +
    <0.196, 0.252, 19.8>,
 +
    <0.310, 0.316, 90.0>,
 +
    <0.310, 0.316, 59.1>,
 +
    <0.310, 0.316, 36.2>,
 +
    <0.310, 0.316, 19.8>,
 +
    <0.310, 0.316, 09.0>,
 +
    <0.310, 0.316, 03.1>
 +
];
 +
 +
vector CIExyY_to_CIEXYZ (vector xyY)
 +
{
 +
    return
 +
    <
 +
        xyY.x * xyY.z / xyY.y,
 +
        xyY.z,
 +
        (1.0 - xyY.x - xyY.y) * xyY.z / xyY.y
 +
    >;
 +
}
 +
 +
vector CIEXYZ_to_RGB709 (vector XYZ)
 +
{
 +
    return
 +
    <
 +
        3.240479 * XYZ.x - 1.53715  * XYZ.y - 0.498535 * XYZ.z,
 +
        -0.969256 * XYZ.x + 1.875991 * XYZ.y + 0.041556 * XYZ.z,
 +
        0.055648 * XYZ.x - 0.204043 * XYZ.y + 1.057311 * XYZ.z
 +
    >;
 +
}
 +
 +
drawChart(integer side)
 +
{
 +
    string drawList = "";
 +
    drawList = osSetPenColor        (drawList, "Black");
 +
    drawList = osMovePen            (drawList, 0, 0);
 +
    drawList = osDrawFilledRectangle (drawList, SIZE, SIZE);
 +
 +
    for (integer row=0; row<NROWS; row++)
 +
        for (integer col=0; col<NCOLS; col++)
 +
        {
 +
            integer colorindex = row*NCOLS + col;
 +
            vector xyYColor = llList2Vector (xyYColors,colorindex);
 +
            vector XYZColor = CIExyY_to_CIEXYZ (xyYColor); // Convert to XYZ space
 +
            vector RGB709  = CIEXYZ_to_RGB709 (XYZColor); // Convert to 'linear' RGB space
 +
            RGB709 *= 0.01;                                // Normalize luminance to ~ 1
 +
            vector sRGB    = llLinear2sRGB (RGB709);      // Apply sRGB gamma
 +
 
 +
            // Color space transformations may produce components outside [0..1]
 +
            // osSetPenColor will take care to clamp the values to this range
 +
 +
            integer pos_y = (row * SIZE/NROWS) +MARGIN;
 +
            integer pos_x = (col * SIZE/NCOLS) +MARGIN;
 +
 
 +
            integer siz_y = (SIZE/NROWS) - (2*MARGIN);
 +
            integer siz_x = (SIZE/NCOLS) - (2*MARGIN);
 +
 +
            drawList = osSetPenColor        (drawList, sRGB);
 +
            drawList = osMovePen            (drawList, pos_x, pos_y);
 +
            drawList = osDrawFilledRectangle (drawList, siz_x, siz_y);
 +
        }
 +
 +
    osSetDynamicTextureDataFace ("", "vector", drawList,
 +
                                  "width:"  +(string)SIZE
 +
                                +", height:" +(string)SIZE,
 +
                                0, side);
 +
}
 +
 +
default
 +
{
 +
    touch_start (integer n)
 +
    {
 +
        drawChart(1);
 +
    }
 +
 +
}</source>
 +
 
 +
|description=
 +
* osSetPenColor(string drawList, string color) Appends a [[Drawing commands#PenColour|PenColor]] drawing command to the string provided in '''drawList''' and returns the result.
 +
 
 +
This sets the pen's drawing color to either the specified [http://msdn.microsoft.com/en-us/library/aa358802.aspx named .NET color] [https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.colors?view=windowsdesktop-6.0 named colors] or to a 32-bit color value (formatted as eight hexadecimal digits in the format aarrggbb, representing the eight-bit alpha, red, green and blue channels).  
  
 
For full opacity, use an alpha value of FF (e.g. <tt>FFFF0000</tt> for red); for varying degrees of transparency, reduce the alpha value (e.g. <tt>800000FF</tt> for semi-transparent blue).  
 
For full opacity, use an alpha value of FF (e.g. <tt>FFFF0000</tt> for red); for varying degrees of transparency, reduce the alpha value (e.g. <tt>800000FF</tt> for semi-transparent blue).  
  
The color names and hexadecimal color representations are not case-sensitive.  
+
The color names and hexadecimal color representations are not case-sensitive.<br>
 +
 
 +
* osSetPenColor(string drawList, vector color) converts vector color to the hexadecimal color with a alpha of 1.0 (FF) and appends the drawing command.
 +
 
 +
* osSetPenColor(string drawList, vector color, float alpha) converts vector color and alpha to the hexadecimal color and appends the drawing command.
 +
 
  
 
'''NOTE :''' This function replaces the deprecated [[OsSetPenColour]] function.
 
'''NOTE :''' This function replaces the deprecated [[OsSetPenColour]] function.
 +
 +
 
|
 
|
 
}}
 
}}

Latest revision as of 10:22, 5 May 2023

string osSetPenColor(string drawList, string color)

string osSetPenColor(string drawList, vector color)
string osSetPenColor(string drawList, vector color, float alpha)

  • osSetPenColor(string drawList, string color) Appends a PenColor drawing command to the string provided in drawList and returns the result.

This sets the pen's drawing color to either the specified named .NET color named colors or to a 32-bit color value (formatted as eight hexadecimal digits in the format aarrggbb, representing the eight-bit alpha, red, green and blue channels).

For full opacity, use an alpha value of FF (e.g. FFFF0000 for red); for varying degrees of transparency, reduce the alpha value (e.g. 800000FF for semi-transparent blue).

The color names and hexadecimal color representations are not case-sensitive.

  • osSetPenColor(string drawList, vector color) converts vector color to the hexadecimal color with a alpha of 1.0 (FF) and appends the drawing command.
  • osSetPenColor(string drawList, vector color, float alpha) converts vector color and alpha to the hexadecimal color and appends the drawing command.


NOTE : This function replaces the deprecated OsSetPenColour function.

Threat Level This function does not do a threat level check
Permissions Use of this function is always allowed by default
Extra Delay 0 seconds
Example(s)
// Example of osSetPenColor
 
string hexDigits = "0123456789abcdef";
list colorNames = [
    "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque",
    "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
    "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
    "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGrey",
    "DarkGreen", "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange",
    "DarkOrchid", "DarkRed", "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue",
    "DarkSlateGrey", "DarkTurquoise", "DarkViolet", "DeepPink", "DeepSkyBlue",
    "DimGrey", "DodgerBlue", "FireBrick", "FloralWhite", "ForestGreen", "Fuchsia",
    "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Grey", "Green", "GreenYellow",
    "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender",
    "LavenderBlush", "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral",
    "LightCyan", "LightGoldenrodYellow", "LightGreen", "LightGrey", "LightPink",
    "LightSalmon", "LightSeaGreen", "LightSkyBlue", "LightSlateGrey",
    "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
    "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple",
    "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise",
    "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin",
    "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab", "Orange", "OrangeRed",
    "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
    "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple",
    "Red", "RosyBrown", "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown",
    "SeaGreen", "Seashell", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGrey",
    "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal", "Thistle", "Tomato",
    "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen"
];
 
default
{
    state_entry()
    {
        // Storage for our drawing commands
        string CommandList = "";
        integer i;
        // Set the pen width to 1 pixel
        CommandList = osSetPenSize(CommandList, 1);
 
        // draw each named color as a single horizontal line
        for (i = 0; i < 140; ++i)
        {
            // Set the pen to the next color name in our list
            CommandList = osSetPenColor(CommandList, llList2String( colorNames, i));
            // Now draw a line in that color
            CommandList = osDrawLine(CommandList, 0, i, 255, i);
        }
 
        // Now let's fill up the remainder with lines of random colors, leaving a gap of 20 lines.
        for (i = 161; i < 256; ++i)
        {
            // give it an opaque alpha
            string thisColor = "ff";
            integer j;
 
            // then choose six random hex digits for the color
            for (j = 0; j < 6; ++j)
            {
                integer k = (integer)llFrand(16.0);
                thisColor += llGetSubString(hexDigits, k, k);
            }
            CommandList = osSetPenColor(CommandList, thisColor);
            CommandList = osDrawLine(CommandList, 0, i, 255, i);
        }
        // Now generate the texture and apply it to the prim
        osSetDynamicTextureData("", "vector", CommandList, "width:256,height:256", 0);
    }
}
// Generating a calibrated color checker
 
integer SIZE    = 512;
integer NROWS   = 4;
integer NCOLS   = 6;
integer MARGIN  = 6;
 
// Color definitions in xyY space
// https://home.cis.rit.edu/~cnspci/references/mccamy1976.pdf
 
list xyYColors = [
    <0.400, 0.350, 10.1>,
    <0.377, 0.345, 35.8>,
    <0.247, 0.251, 19.3>,
    <0.337, 0.422, 13.3>,
    <0.265, 0.240, 24.3>,
    <0.261, 0.343, 43.1>,
    <0.506, 0.407, 30.1>,
    <0.211, 0.175, 12.0>,
    <0.453, 0.306, 19.8>,
    <0.285, 0.202, 6.60>,
    <0.380, 0.489, 44.3>,
    <0.473, 0.438, 43.1>,
    <0.187, 0.129, 06.1>,
    <0.305, 0.478, 23.4>,
    <0.539, 0.313, 12.0>,
    <0.448, 0.470, 59.1>,
    <0.364, 0.233, 19.8>,
    <0.196, 0.252, 19.8>,
    <0.310, 0.316, 90.0>,
    <0.310, 0.316, 59.1>,
    <0.310, 0.316, 36.2>,
    <0.310, 0.316, 19.8>,
    <0.310, 0.316, 09.0>,
    <0.310, 0.316, 03.1>
];
 
vector CIExyY_to_CIEXYZ (vector xyY)
{
    return 
    <
        xyY.x * xyY.z / xyY.y,
        xyY.z,
        (1.0 - xyY.x - xyY.y) * xyY.z / xyY.y
    >;
}
 
vector CIEXYZ_to_RGB709 (vector XYZ)
{
    return 
    <
         3.240479 * XYZ.x - 1.53715  * XYZ.y - 0.498535 * XYZ.z,
        -0.969256 * XYZ.x + 1.875991 * XYZ.y + 0.041556 * XYZ.z,
         0.055648 * XYZ.x - 0.204043 * XYZ.y + 1.057311 * XYZ.z
    >;
}
 
drawChart(integer side)
{
    string drawList = "";
    drawList = osSetPenColor         (drawList, "Black");
    drawList = osMovePen             (drawList, 0, 0);
    drawList = osDrawFilledRectangle (drawList, SIZE, SIZE);
 
    for (integer row=0; row<NROWS; row++)
        for (integer col=0; col<NCOLS; col++)
        {
            integer colorindex = row*NCOLS + col;
            vector xyYColor = llList2Vector (xyYColors,colorindex);
            vector XYZColor = CIExyY_to_CIEXYZ (xyYColor); // Convert to XYZ space
            vector RGB709   = CIEXYZ_to_RGB709 (XYZColor); // Convert to 'linear' RGB space
            RGB709 *= 0.01;                                // Normalize luminance to ~ 1
            vector sRGB     = llLinear2sRGB (RGB709);      // Apply sRGB gamma
 
            // Color space transformations may produce components outside [0..1]
            // osSetPenColor will take care to clamp the values to this range
 
            integer pos_y = (row * SIZE/NROWS) +MARGIN;
            integer pos_x = (col * SIZE/NCOLS) +MARGIN;
 
            integer siz_y = (SIZE/NROWS) - (2*MARGIN);
            integer siz_x = (SIZE/NCOLS) - (2*MARGIN);
 
            drawList = osSetPenColor         (drawList, sRGB);
            drawList = osMovePen             (drawList, pos_x, pos_y);
            drawList = osDrawFilledRectangle (drawList, siz_x, siz_y);
        }
 
    osSetDynamicTextureDataFace ("", "vector", drawList, 
                                   "width:"  +(string)SIZE
                                +", height:" +(string)SIZE,
                                0, side);
}
 
default
{
    touch_start (integer n)
    {
        drawChart(1);
    }
 
}
Notes
This function was added in 0.7.2-post-fixes; Variants with vector and alpha arguments added in 0.9.3.0


Personal tools
General
About This Wiki