Export As: [ PDF | ODT ]

Defining a Color Value

All color values in the Style DOM are specified by a short DAZ Script statement. This allows a great amount of flexibility in specifying color values, and much greater range of logic than could be provided by a set of simple parser-supported syntax.

The statement must evaluate to a color value in order to be valid. To this end, 4 global functions that return a Color are provided:

function RGB( Number red, Number green, Number blue ) {...};
function RGBA( Number red, Number green, Number blue, int alpha ) {...};
function HSV( Number hue, Number saturation, Number value ) {...};
function HSVA( Number hue, Number saturation, Number value, Number alpha ) {...};

The valid range for the parameters are:

  • red - [0, 255]
  • green - [0, 255]
  • blue - [0, 255]
  • alpha - [0, 255]
  • hue - [0, 359]
  • saturation - [0, 255]
  • value - [0, 255]

Using these functions, it becomes very easy to construct a color from an RGB or HSV value. For example, the color red would be specified by the statement “RGB( 255, 0, 0 )” or “HSV( 0, 255, 255 )”. An alpha value can be used to create a color with transparency. A semi-transparent red would be specified by the statement “RGBA( 255, 0, 0, 128 )” or “HSVA( 0, 255, 255, 128 )”.

Also provided are Color objects. In DAZ Script, these objects would be defined as follows:

function Color(){
    this.R, this.G, this.B, this.H, this.S, this.V, this.A,
    this.light = function( nAmount ) {...},
    this.dark = function( nAmount ) {...};
};

The members are:

  • R - The red component of the color as an integer in the range [0, 255].
  • G - The green component of the color as an integer in the range [0, 255].
  • B - The blue component of the color as an integer in the range [0, 255].
  • H - The hue component of the color as an integer in the range [0, 359].
  • S - The saturation component of the color as an integer in the range [0, 255].
  • V - The value component of the color as an integer in the range [0, 255].
  • A - The alpha component of the color as an integer in the range [0, 255].
  • light - A method that returns a lighter version of the color.
    • The parameter nAmount is an integer that specifies the percentage lighter that the return value is than the original color.
  • dark - A method that returns a darker version of the color.
    • The parameter nAmount is an integer that specifies the percentage darker that the return value is than the original color.

Each UserColor, StyleColor and Color element in the Style Definition will be available as a color object with the matching Name|Role. So, to specify a color that is the same as the standard background color, you could use the statement “Window”. You could specify a darker version of the background color with the statement “Window.dark( 110 )”, or a lighter version of the background color with the statement “Window.light( 160 )”.

Another way to get a lighter version of the background color would be to use its HSV values, and lighten it by adding to the value component, for example, a statement like this would work: “HSV( Window.H, Window.S, Window.V + 70 )”, or you could create a color that used only the red channel from the foreground color with a statement like: “RGB( WindowText.R, 0, 0 )”.

One way to make the style very flexible is to use UserColor elements. For example, say you create a UserColor named “BGColor” and one named “TextColor” - this would allow the user to pick custom values for these colors. You can then make your style use these custom colors by using their Name in your color statements. For example, “BGColor” may be the color you want for the Window Color, so the Value statement for the Window Color would simply be “BGColor” and it would use the Value that the user specified for the UserColor named “BGColor”. You may want to use a lighter version of BGColor for the standard Button Color, so you could use the statement “BGColor.light( 100 )”.

Since these statements are scripts, you can use matematical statements and even conditional (ternary) statements to make your color definitions very flexible.