Sign in to follow this  
Followers 0
zorphnog

WebColors UDF

1 post in this topic

#1 ·  Posted (edited)

Utility functions for color names and color value formats defined by the HTML and CSS specifications for use in documents on the Web.

What this UDF supports

-------------------------

This UDF supports the following methods of specifying RGB colors, and conversions between them:

  • Six-digit hexadecimal.
  • Three-digit hexadecimal.
  • Integer 3-element RGB array.
  • Percentage 3-element RGB array.
  • Varying selections of predefined color names.
WebColors.au3

#include-once
; #INDEX# =======================================================================================================================
; Title .........: WebColors
; AutoIt Version : 3.3.8++
; Language ......: English
; Description ...: Functions for converting html/css color codes. Ported from Python implementation by James Bennett, BitBucket
;                 for original code. [https://bitbucket.org/ubernostrum/webcolors/]
; Author(s) .....: Michael Mims (zorphnog)
;                 OHB <me at="" orangehairedboy="" dot="" com=""> (__WebColors_x UDF)
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_WebColors_HexToName
;_WebColors_HexToRGB
;_WebColors_HexToRGBPercent
;_WebColors_NameToHex
;_WebColors_NameToRGB
;_WebColors_NameToRGBPercent
;_WebColors_RGBToName
;_WebColors_RGBToHex
;_WebColors_RGBToRGBPercent
;_WebColors_RGBPercentToName
;_WebColors_RGBPercentToHex
;_WebColors_RGBPercentToRGB
; ===============================================================================================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
;__WebColors_Init
;__WebColors_InitCSS21
;__WebColors_InitCSS3
;__WebColors_InitHTML4
;__WebColors_IsValidRGB
;__WebColors_Normalize_Hex
;__WebColors_PercentToInt
;__WebColors_Reverse_Dict
;__WebColors_x
; ===============================================================================================================================
Global Const $__WC_HEX_COLOR_RE = "A#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})z"
Global Const $__WC_SUPPORTED_SPECIFICATIONS[4] = ['html4', 'css2', 'css21', 'css3']
Global Const _
    $__WC_HTML4_NAMES_TO_HEX = "html4_ntoh", _
    $__WC_HTML4_HEX_TO_NAMES = "html4_hton", _
    $__WC_CSS2_NAMES_TO_HEX  = $__WC_HTML4_NAMES_TO_HEX, _
    $__WC_CSS2_HEX_TO_NAMES  = $__WC_HTML4_HEX_TO_NAMES, _
    $__WC_CSS21_NAMES_TO_HEX = "css21_ntoh", _
    $__WC_CSS21_HEX_TO_NAMES = "css21_hton", _
    $__WC_CSS3_NAMES_TO_HEX  = "css3_ntoh", _
    $__WC_CSS3_HEX_TO_NAMES  = "css3_hton"
Global $__WC_DICT_INITIALIZED = False, $__WC_xHashCollection = ObjCreate( "Scripting.Dictionary" )

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToName
; Description ...: Convert a hexadecimal color value to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_HexToName($hex_value[, $spec = 'css3'])
; Parameters ....: $hex_value          - The hexadecimal color value.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name of the hexadecimal value
;                 Failure - Blank string, sets @error
;                 |1 - Specification not supported
;                 |2 - Hex value is not a valid hexadecimal color value
;                 |3 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToName($hex_value, $spec='css3')
    __WebColors_Init()
    Local $dict, $name, $normalized
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_HEX_TO_NAMES
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $normalized = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(1 + @error, 0, "")  ; value is not valid hexadecimal color value
    $name = __WebColors_x($dict & "." & $normalized)
    If $name <> "" Then Return $name
    Return SetError(3, 0, "")                         ; hex_value has no defined color name
EndFunc   ;==>_WebColors_HexToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGB
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB integers.
; Syntax ........: _WebColors_HexToRGB($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of integer values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGB($hex_value)
    Local $hex_digits, $rgb_value[3]
    $hex_digits = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(@error, 0, "")     ; value is not valid hexadecimal color value
    $rgb_value[0] = Int('0x' & StringMid($hex_digits, 2, 2))
    $rgb_value[1] = Int('0x' & StringMid($hex_digits, 4, 2))
    $rgb_value[2] = Int('0x' & StringMid($hex_digits, 6, 2))
    Return $rgb_value
EndFunc   ;==>_WebColors_HexToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGBPercent
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_HexToRGBPercent($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of percentage values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
;                 |2 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGBPercent($hex_value)
    Local $rgb_value
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then Return SetError(1 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_HexToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Init
; Description ...: Initializes the color dictionary.
; Syntax ........: __WebColors_Init()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Init()
    If Not $__WC_DICT_INITIALIZED Then
        __WebColors_InitHTML4()
        __WebColors_InitCSS21()
        __WebColors_InitCSS3()
        __WebColors_Reverse_Dict($__WC_HTML4_NAMES_TO_HEX, $__WC_HTML4_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS21_NAMES_TO_HEX, $__WC_CSS21_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS3_NAMES_TO_HEX, $__WC_CSS3_HEX_TO_NAMES)
        $__WC_DICT_INITIALIZED = True
    EndIf
EndFunc   ;==>__WebColors_Init
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS21
; Description ...: Adds the CSS 2.1 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS21()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS21()
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitCSS21
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS3
; Description ...: Adds the CSS 3 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS3()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS3()
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aliceblue', '#f0f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.antiquewhite', '#faebd7')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aquamarine', '#7fffd4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.azure', '#f0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.beige', '#f5f5dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.bisque', '#ffe4c4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blanchedalmond', '#ffebcd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blueviolet', '#8a2be2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.brown', '#a52a2a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.burlywood', '#deb887')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cadetblue', '#5f9ea0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chartreuse', '#7fff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chocolate', '#d2691e')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.coral', '#ff7f50')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornflowerblue', '#6495ed')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornsilk', '#fff8dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.crimson', '#dc143c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cyan', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkblue', '#00008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkcyan', '#008b8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgoldenrod', '#b8860b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgray', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgrey', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgreen', '#006400')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkkhaki', '#bdb76b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkmagenta', '#8b008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkolivegreen', '#556b2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorange', '#ff8c00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorchid', '#9932cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkred', '#8b0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darksalmon', '#e9967a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkseagreen', '#8fbc8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslateblue', '#483d8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategray', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategrey', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkturquoise', '#00ced1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkviolet', '#9400d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deeppink', '#ff1493')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deepskyblue', '#00bfff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgray', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgrey', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dodgerblue', '#1e90ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.firebrick', '#b22222')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.floralwhite', '#fffaf0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.forestgreen', '#228b22')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gainsboro', '#dcdcdc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ghostwhite', '#f8f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gold', '#ffd700')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.goldenrod', '#daa520')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gray', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.greenyellow', '#adff2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.honeydew', '#f0fff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.hotpink', '#ff69b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indianred', '#cd5c5c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indigo', '#4b0082')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ivory', '#fffff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.khaki', '#f0e68c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavender', '#e6e6fa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavenderblush', '#fff0f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lawngreen', '#7cfc00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lemonchiffon', '#fffacd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightblue', '#add8e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcoral', '#f08080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcyan', '#e0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgoldenrodyellow', '#fafad2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgray', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgrey', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgreen', '#90ee90')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightpink', '#ffb6c1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsalmon', '#ffa07a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightseagreen', '#20b2aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightskyblue', '#87cefa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategray', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategrey', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsteelblue', '#b0c4de')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightyellow', '#ffffe0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.limegreen', '#32cd32')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.linen', '#faf0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.magenta', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumaquamarine', '#66cdaa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumblue', '#0000cd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumorchid', '#ba55d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumpurple', '#9370d8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumseagreen', '#3cb371')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumslateblue', '#7b68ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumspringgreen', '#00fa9a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumturquoise', '#48d1cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumvioletred', '#c71585')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.midnightblue', '#191970')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mintcream', '#f5fffa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mistyrose', '#ffe4e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.moccasin', '#ffe4b5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navajowhite', '#ffdead')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.oldlace', '#fdf5e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olivedrab', '#6b8e23')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orangered', '#ff4500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orchid', '#da70d6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegoldenrod', '#eee8aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegreen', '#98fb98')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.paleturquoise', '#afeeee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palevioletred', '#d87093')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.papayawhip', '#ffefd5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peachpuff', '#ffdab9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peru', '#cd853f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.pink', '#ffc0cb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.plum', '#dda0dd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.powderblue', '#b0e0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.rosybrown', '#bc8f8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.royalblue', '#4169e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.saddlebrown', '#8b4513')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.salmon', '#fa8072')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sandybrown', '#f4a460')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seagreen', '#2e8b57')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seashell', '#fff5ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sienna', '#a0522d')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.skyblue', '#87ceeb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slateblue', '#6a5acd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategray', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategrey', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.snow', '#fffafa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.springgreen', '#00ff7f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.steelblue', '#4682b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tan', '#d2b48c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.thistle', '#d8bfd8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tomato', '#ff6347')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.turquoise', '#40e0d0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.violet', '#ee82ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.wheat', '#f5deb3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.whitesmoke', '#f5f5f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellow', '#ffff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellowgreen', '#9acd32')
EndFunc   ;==>__WebColors_InitCSS3
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitHTML4
; Description ...: Adds the HTML 4 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitHTML4()
; Parameters ....:
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitHTML4()
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitHTML4
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_IsValidRGB
; Description ...: Determines whether a RGB array is valid.
; Syntax ........: __WebColors_IsValidRGB($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB values.
; Return values .: Success - True
;                 Failure - False, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_IsValidRGB($rgb_value)
    If Not IsArray($rgb_value) Then Return SetError(1, 0, False)
    If UBound($rgb_value) <> 3 Then Return SetError(2, 0, False)
    For $i=0 To 2
        If Number($rgb_value[$i]) > 255 Or Number($rgb_value[$i]) < 0 Then Return SetError(3, 0, False)
    Next
    Return True
EndFunc   ;==>__WebColors_IsValidRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToHex
; Description ...: Convert a color name to a normalized hexadecimal color value.
; Syntax ........: _WebColors_NameToHex($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The hex value of the color
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToHex($name, $spec='css3')
    __WebColors_Init()
    Local $dict, $hex_value
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_NAMES_TO_HEX
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $hex_value = __WebColors_x($dict & "." & $name)
    If $hex_value <> "" Then Return $hex_value
    Return SetError(2, 0, "")
EndFunc   ;==>_WebColors_NameToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGB
; Description ...: Convert a color name to a 3-element array of integers.
; Syntax ........: _WebColors_NameToRGB($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the integer values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGB($name, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $rgb_value
    $hex_value = _WebColors_NameToHex($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(2 + @error, 0, "")
    Return $rgb_value
EndFunc   ;==>_WebColors_NameToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGBPercent
; Description ...: Convert a color name to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_NameToRGBPercent($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the percentage values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
;                 |4 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGBPercent($name, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $rgb_percent
    $rgb_value = _WebColors_NameToRGB($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then SetError(4 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_NameToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Normalize_Hex
; Description ...: Normalize a hexadecimal color value to the following form and return the result: #[a-f0-9]{6}
; Syntax ........: __WebColors_Normalize_Hex($hex_value)
; Parameters ....: $hex_value          - A hexadecimal color value to normalize.
; Return values .: Success - The normalized hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Normalize_Hex($hex_value)
    Local $aReturn, $hex_digits
    $aReturn = StringRegExp($hex_value, $__WC_HEX_COLOR_RE, 3)
    If @error Then Return SetError(1, 0, "")
    $hex_digits = $aReturn[0]
    If StringLen($hex_digits) == 3 Then
        $hex_digits = StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 2, 1) & _
            StringMid($hex_digits, 2, 1) & StringMid($hex_digits, 3, 1) & StringMid($hex_digits, 3, 1)
    EndIf
    Return StringFormat("#%s", StringLower($hex_digits))
EndFunc   ;==>__WebColors_Normalize_Hex
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_PercentToInt
; Description ...: Internal helper for converting a percentage value to an integer between 0 and 255 inclusive.
; Syntax ........: __WebColors_PercentToInt($percent)
; Parameters ....: $percent          - A percentage value.
; Return values .: The rounded integer value of the percentage of 255
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_PercentToInt($percent)
    Return Round(Number(StringTrimRight($percent, 1)) / 100.0 * 255)
EndFunc   ;==>__WebColors_PercentToInt

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToName
; Description ...: Convert a 3-element array of integers to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBToName($rgb_value[, $spec = 'css3'])
; Parameters ....: $rgb_value          - An array of RGB integer values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToName($rgb_value, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $name
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_HexToName($hex_value, $spec)
    If @error Then Return SetError(3 + @error, 0, "")
    Return $name
EndFunc   ;==>_WebColors_RGBToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToHex
; Description ...: Convert a 3-element array of integers to a normalized hexadecimal value for that color.
; Syntax ........: _WebColors_RGBToHex($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The normalized hex value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToHex($rgb_value)
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    Return StringFormat("#%02x%02x%02x", Int($rgb_value[0]), Int($rgb_value[1]), Int($rgb_value[2]))
EndFunc   ;==>_WebColors_RGBToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToRGBPercent
; Description ...:  Convert a 3-element array of RGB integers to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_RGBToRGBPercent($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The 3-element array of RGB percentages
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToRGBPercent($rgb_value)
    Local $rgb_percent[3]
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    For $i=0 To 2
        Switch Int($rgb_value[$i])
            Case 255
                $rgb_percent[$i] = "100%"
            Case 128
                $rgb_percent[$i] = "50%"
            Case 64
                $rgb_percent[$i] = "25%"
            Case 32
                $rgb_percent[$i] = "12.5%"
            Case 16
                $rgb_percent[$i] = "6.25%"
            Case 0
                $rgb_percent[$i] = "0%"
            Case Else
                $rgb_percent[$i] = StringFormat("%.02f%%", ($rgb_value[$i] / 255.0) * 100)
        EndSwitch
    Next
    Return $rgb_percent
EndFunc   ;==>_WebColors_RGBToRGBPercent
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToName
; Description ...:  Convert a 3-element array of percentages to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBPercentToName($rgb_percent[, $spec = 'css3'])
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToName($rgb_percent, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $name
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_RGBToName($rgb_value, $spec)
    If @error Then Return SetError(@error)
    Return $name
EndFunc   ;==>_WebColors_RGBPercentToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToHex
; Description ...: Convert a 3-element array of percentages to a normalized hexadecimal color value for that color.
; Syntax ........: _WebColors_RGBPercentToHex($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToHex($rgb_percent)
    Local $rgb_value, $hex_value
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    Return $hex_value
EndFunc   ;==>_WebColors_RGBPercentToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToRGB
; Description ...: Convert a 3-element array of percentages to a 3-element array of integers.
; Syntax ........: _WebColors_RGBPercentToRGB($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The 3-element array of RGB integers
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToRGB($rgb_percent)
    Local $rgb_value[3]
    If Not __WebColors_IsValidRGB($rgb_percent) Then Return SetError(@error, 0, "")
    For $i=0 To 2
        $rgb_value[$i] = __WebColors_PercentToInt($rgb_percent[$i])
    Next
    Return $rgb_value
EndFunc   ;==>_WebColors_RGBPercentToRGB
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Reverse_Dict
; Description ...: Creates a reverse lookup dictionary.
; Syntax ........: __WebColors_Reverse_Dict($base_dict, $reverse_dict)
; Parameters ....: $base_dict          - A dictionary to reverse.
;                 $reverse_dict     - A dictionary to store the reversed dictionary.
; Return values .: Success - None
;                 Failure - -1, sets @error to 1
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Reverse_Dict($base_dict, $reverse_dict)
    Local $items = __WebColors_x($base_dict)
    If IsObj($items) Then
        For $i In $items
            __WebColors_x($reverse_dict & "." & $items.item($i), $i)
        Next
    Else
        Return SetError(1, 0, -1)
    EndIf
EndFunc   ;==>__WebColors_Reverse_Dict
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __WebColors_x
; Description ...: Gets or sets a value in an Associative Array
; Syntax.........: SET: __WebColors_x( $sKey , $vValue )
;                 GET: __WebColors_x( $key )
; Parameters ....: $sKey - the key to set or get. Examples:
;                 __WebColors_x( 'foo' )           gets value of foo
;                 __WebColors_x( 'foo.bar' )       gets value of bar which is a key of foo
;                 $bar = "baz"
;                 __WebColors_x( 'foo.$bar' )     gets value of baz which is a key of foo (variables are expanded)
; Return values .: Success - When setting, return the value set. When getting, returns the requested value.
;                 Failure - Returns a 0
; Author ........: OHB <me at="" orangehairedboy="" dot="" com="">
; ===============================================================================================================================
Func __WebColors_x( $sKey = '' , $vValue = '' )
    $func = "get"
    If @NumParams <> 1 Then $func = "set"
    If $sKey == '' Then
        If $func == "get" Then
            Return $__WC_xHashCollection
        Else
            $__WC_xHashCollection.removeAll
            Return ''
        EndIf
    EndIf
    $parts = StringSplit( $sKey , "." )
    $last_key = $parts[$parts[0]]
    $cur = $__WC_xHashCollection
    For $x = 1 To $parts[0] - 1
        If Not $cur.exists( $parts[$x] ) Then
            If $func == "get" Then Return
            $cur.add( $parts[$x] , ObjCreate( "Scripting.Dictionary" ) )
        EndIf
        $cur = $cur.item( $parts[$x] )
    Next
    If IsPtr( $vValue ) Then $vValue = String( $vValue )
    If $func == "get" Then
        If Not $cur.exists( $last_key ) Then Return
        $item = $cur.item( $last_key )
        Return $item
    ElseIf Not $cur.exists( $last_key ) Then
        $cur.add( $last_key , $vValue )
    Else
        $cur.item( $last_key ) = $vValue
    EndIf
    Return $vValue
EndFunc

_WebColors_Test.au3

#include "WebColors.au3"
#include <array.au3>
Global $sLog = ""
$sLog &= __GetTestResult("_WebColors_NameToHex('white')", '#ffffff')
$sLog &= __GetTestResult("_WebColors_NameToHex('navy')", '#000080')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod')", '#daa520')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod', 'html4')", 2) ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_NameToRGB('white')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('navy')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('goldenrod')", '[218, 165, 32]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('white')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('navy')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('goldenrod')", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_HexToName('#ffffff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#fff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#000080')", 'navy')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520')", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520', 'html4')", 3)   ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_HexToRGB('#fff')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_HexToRGB('#000080')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#ffffff')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#000080')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(255, 255, 255))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(0, 0, 128))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(255, 255, 255))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(0, 0, 128))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(255, 255, 255))", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(0, 0, 128))", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(218, 165, 32))", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('100%', '100%', '100%'))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('0%', '0%', '50%'))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('85.49%', '64.71%', '12.5%'))", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('100%', '100%', '100%'))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('0%', '0%', '50%'))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '#daa520')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('100%', '100%', '100%'))", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('0%', '0%', '50%'))", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '[218, 165, 32]')
ConsoleWrite($sLog)
Func __GetTestResult($sCommand, $sExpected = "")
    Local $sResult, $iError, $sPass
    $sResult = Execute($sCommand)
    $iError = @error
    $sPass = "!FAIL"
    Select
        Case $iError <> 0
            If $iError == $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => <error: %d="">n", $sPass, $sCommand, $iError)
        Case IsString($sResult)
            If $sResult = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn", $sPass, $sCommand, $sResult)
        Case IsArray($sResult)
            Local $sTemp = "[" & _ArrayToString($sResult, ", ") & "]"
            If $sTemp = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn",$sPass, $sCommand, $sTemp)
    EndSelect
EndFunc

UDF + Test script:

WebColors.zip

Edited by zorphnog

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • SkysLastChance
      By SkysLastChance
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("website") Local $oForms = _IEFormGetCollection($oIE) For $oForm In $oForms MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name) _IEImgClick($oForm.name, "Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=12.0.5522.0&amp;Name=Microsoft.ReportingServices.Rendering.HtmlRenderer.RendererResources.TogglePlus.gif", "src") Next I am having trouble clicking an image. Here is what I have tried. 

    • Jefrey
      By Jefrey
      I've made this HTTP lib to simplify HTTP requests, mainly when dealing about POST data or file uploads.
      Three functions are available:
      string _HTTP_Get ( string $sURL ) string _HTTP_Post ( string $sURL , string $sPostData ) string _HTTP_Upload ( string $sURL , string $sFilePath , string $sFileField , string $sPostData = '' , string $sFilename = Default) Additionaly, two helper functions are also available:
      URLEncode($sStr) URLDecode($sStr) Full documentation: https://github.com/jesobreira/HTTP.au3/blob/master/README.md
      Fork me on Github: https://github.com/jesobreira/HTTP.au3
      Download lib + docs: https://github.com/jesobreira/HTTP.au3/archive/master.zip
    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi!
      Does anyone have any idea why Test() returns 0, while Test2() returns 1?
      #include <IE.au3> MsgBox(0, "", Test() & " " & Test2()) Func Test() Local $oHTML = ObjCreate("HTMLFILE") $oHTML.body.innerHTML = FileRead("Test.html") Return IsObj($oHTML.getElementsByClassName("example")) EndFunc Func Test2() Local $oIE = _IEAttach("", "instance", 1) Return IsObj($oIE.document.getElementsByClassName("example")) EndFunc Sample Test.html I open in IE before testing:
      <!DOCTYPE html> <html> <body> <p class="example"></p> <div class="example"></div> </body> </html> I'm receiving html text in a response to http request, I need to parse it fast and easy, getElementsByClassName would have been ideal. I'm using 3.3.12.0 version.
    • seppedelanghe
      By seppedelanghe
      Hi everyone,
      First of all sorry for my bad english.
      I'm trying to build a automated program/autoit that controls a web app.
      I created the script using mouseclick() , but i don't want the web browser to be visible.
      I tried ControlClick() , but the web app uses flash and the buttons/items to be clicked do not have an ID.
      I searched and visited a lott of autoit post and pages (even in german  ) , but could not find a way or get it to work.
      Any help is welcome!!!
      Thanks already
      Seppe
    • messilm10
      By messilm10
      respected sir,
      how could I calculate the time difference using auto IT function ?