Jump to content

Search the Community

Showing results for tags 'colors'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 10 results

  1. ScreenColorPicker snap color from screen with the mouse pointer to clipboard the idea comes from @Melba23's Magnify post. Thanks for that! ;https://www.autoitscript.com/forum/topic/209412-screencolorpicker-snap-color-from-screen-with-the-mouse-pointer/ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;ScreenColorPicker.au3 ;snap color from screen with the mouse pointer #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <Misc.au3> #include <StringConstants.au3> #include <TrayConstants.au3> ; to avoid running it multiple times! If _Singleton(@ScriptName, 1) = 0 Then Exit Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode. Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aMouse_Pos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0 Local $mColor, $hColor_Win, $ColorLabel, $ColorRec TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico") TraySetToolTip("ColorPicker") #Region === Tray_Menu === ;~ Local $idPaused = TrayCreateItem("Pause", -1, -1, $TRAY_ITEM_RADIO) ;~ TrayItemSetState(-1, $TRAY_UNCHECKED) Local $TrayColorPicker = TrayCreateItem("ColorPicker") Local $TrayHelp = TrayCreateItem("Help") TrayCreateItem("") ; Create a separator line. Local $TrayExit = TrayCreateItem("Exit") #EndRegion === Tray_Menu === Local $hDLL = DllOpen("user32.dll") While 1 Switch TrayGetMsg() Case $TRAY_EVENT_PRIMARYDOUBLE ;* ColorPicker ColorPicker() Case $TrayColorPicker ; ColorPicker ColorPicker() Case $TrayHelp ; Help HelpInfo() Case $TrayExit ; Exit GoToExit() EndSwitch ;if END key close ColorPicker If _IsPressed("23", $hDLL) Then Sleep(300) ColorPicker() EndIf Sleep(50) WEnd GoToExit() ;---------------------------------------------------------------------------------------- Func GoToExit() ; exit CloseColorPicker() DllClose($hDLL) Exit EndFunc ;==>GoToExit ;---------------------------------------------------------------------------------------- Func ColorPicker() ; Create Color GUI $hColor_Win = GUICreate("Color", 100, 30, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUICtrlCreateLabel("Label1", 0, 0, 100, 30, $SS_BLACKFRAME) $ColorLabel = GUICtrlCreateLabel(" ", 26, 7, 74, 20) $ColorRec = GUICtrlCreateLabel(" ", 1, 1, 25, 28) GUICtrlSetFont($ColorLabel, 10, 600, 0, "Consolas") GUICtrlSetBkColor($ColorLabel, $GUI_BKCOLOR_TRANSPARENT) GUISetState(@SW_SHOW, $hColor_Win) ; Create MAG GUI $hMag_GUI = GUICreate("MAG", 100, 100, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetState(@SW_SHOW, $hMag_GUI) ; Get device context for Mag GUI $hMagDC = _WinAPI_GetDC($hMag_GUI) If @error Then Exit ; Get device context for desktop $hDeskDC = _WinAPI_GetDC(0) If @error Then _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) Exit EndIf ; Create pen $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E) $oObj = _WinAPI_SelectObject($hMagDC, $hPen) While 1 ; Check if cursor has moved $aMouse_Pos = MouseGetPos() If $aMouse_Pos[0] <> $iLast_Mouse_X Or $aMouse_Pos[1] <> $iLast_Mouse_Y Then ; Redraw Mag GUI Loupe($aMouse_Pos) ; Reset position $iLast_Mouse_X = $aMouse_Pos[0] $iLast_Mouse_Y = $aMouse_Pos[1] EndIf Select Case _IsPressed("02", $hDLL) Or _IsPressed("10", $hDLL) ; 02 = Right mouse button ; 10 = SHIFT key TakeSnap() Return Case _IsPressed("23", $hDLL) ;23 END key TakeSnap() Return Case _IsPressed("1B", $hDLL) ;1B = ESC key CloseColorPicker() Return Case _IsPressed("25", $hDLL) ; 25 = LEFT ARROW key MouseMove($aMouse_Pos[0] - 1, $aMouse_Pos[1]) Sleep(100) Case _IsPressed("26", $hDLL) ; 26 = UP ARROW key MouseMove($aMouse_Pos[0], $aMouse_Pos[1] - 1) Sleep(100) Case _IsPressed("27", $hDLL) ; 27 = RIGHT ARROW key MouseMove($aMouse_Pos[0] + 1, $aMouse_Pos[1]) Sleep(100) Case _IsPressed("28", $hDLL) ; 28 = DOWN ARROW key MouseMove($aMouse_Pos[0], $aMouse_Pos[1] + 1) Sleep(100) EndSelect WEnd EndFunc ;==>ColorPicker ;---------------------------------------------------------------------------------------- Func Loupe($aMouse_Pos) Local $iX, $iY ; Fill Mag GUI with 10x expanded contents of desktop area (5 pixels around mouse) DllCall("gdi32.dll", "int", "StretchBlt", _ "int", $hMagDC, "int", 0, "int", 0, "int", 100, "int", 100, _ "int", $hDeskDC, "int", $aMouse_Pos[0] - 5, "int", $aMouse_Pos[1] - 5, "int", 10, "int", 10, _ "long", $SRCCOPY) ; Original 10 x 10 expanded to 100 x 100 - 10x magnification $mColor = PixelGetColor($aMouse_Pos[0], $aMouse_Pos[1]) $mColor = "0x" & Hex($mColor, 6) ; * <-------------- color converted to hexadecimal GUICtrlSetData($ColorLabel, $mColor) GUICtrlSetBkColor($ColorRec, $mColor) ; Keep Mag GUI on screen If $aMouse_Pos[0] < (@DesktopWidth - 120) Then $iX = $aMouse_Pos[0] + 20 Else $iX = $aMouse_Pos[0] - 120 EndIf If $aMouse_Pos[1] < (@DesktopHeight - 150) Then $iY = $aMouse_Pos[1] + 20 Else $iY = $aMouse_Pos[1] - 120 EndIf WinMove($hMag_GUI, "", $iX, $iY, 100, 100) WinMove($hColor_Win, "", $iX, $iY + 100) EndFunc ;==>Loupe ;---------------------------------------------------------------------------------------- Func TakeSnap() ClipPut($mColor) ConsoleWrite($mColor & @CRLF) WinMove($hColor_Win, "", @DesktopWidth - 120, @DesktopHeight - 75) GUISetState(@SW_HIDE, $hMag_GUI) WinWait("[CLASS:#32768]", "", 1) If WinExists("[CLASS:#32768]") Then Send("{ESC}") Sleep(3000) CloseColorPicker() EndFunc ;==>TakeSnap ;---------------------------------------------------------------------------------------- Func CloseColorPicker() ; Clear up Mag GUI _WinAPI_SelectObject($hMagDC, $oObj) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDeskDC) _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) GUIDelete($hMag_GUI) GUIDelete($hColor_Win) EndFunc ;==>CloseColorPicker ;---------------------------------------------------------------------------------------- Func HelpInfo() Local $Msg = @CRLF & "HotKey {END} call ColorPicker." & @CRLF & @CRLF _ & "During ColorPicker is active" & @CRLF & @CRLF _ & "{END} or {SHIFT} or Right mouse button" & @TAB & @CRLF _ & "snap the Color to clipboard " & @CRLF & @CRLF _ & "{LEFT}, {UP}, {RIGHT}, {DOWN}" & @CRLF _ & "moves the mouse by 1 pixel" & @CRLF & @CRLF _ & "{ESC} close ColorPicker to tray" & @CRLF & @CRLF _ & "---> Press {ESC} to exit <--- " & @CRLF _ & " " & @CRLF ToolTip($Msg, @DesktopWidth / 2, @DesktopHeight / 5, "info", 1) GUICtrlSetFont(-1, 14, 600, 0, "Arial") Do Sleep(100) Until _IsPressed("1B", $hDLL) ; 1B ESC key ToolTip("") EndFunc ;==>HelpInfo Please, leave your suggestion , comments , experiences here. Thank you!
  2. #include <GDIPlus.au3> Example() Func Example() Local $hImage1, $hGraphics Local Const $iWidth = 100, $iHeight = 100 ; Initialize GDI+ library _GDIPlus_Startup() $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\p0.bmp") ; Draw one image in another $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1) Local $aRemapTable[4][2] $aRemapTable[0][0] = 3 $aRemapTable[1][0] = 0xFF2D1200 ;Old Color1 $aRemapTable[1][1] = 0xFF000000 ;New Color1 $aRemapTable[2][0] = 0xFF491D00 ;Old Color2 $aRemapTable[2][1] = 0xFF000000 ;New Color2 $aRemapTable[3][0] = 0xFF381600 ;Old Color3 $aRemapTable[3][1] = 0xFF000000 ;New Color3 Local $hIA = _GDIPlus_ImageAttributesCreate() _GDIPlus_ImageAttributesSetRemapTable($hIA, $aRemapTable) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage1, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ; Save resultant image _GDIPlus_ImageSaveToFile($hImage1, @ScriptDir & "\p1.bmp") ; Clean up resources _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hImage1) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>Example https://i.postimg.cc/ZYXCH5MQ/p0.png https://i.postimg.cc/0jS5F7BB/p1.png Hello, Is there a quick way to use "gdi" to convert the image "p0.bmp" to "p1.bmp"? With "_GDIPlus_ImageAttributesSetRemapTable" I could convert the relevant pixels to the desired color. Now I just need a quick function to replace the remaining non-relevant pixels with white "0xFFFFFFFF". thanks in advance p1.bmp p0.bmp
  3. This is kind of a side question but it has always driven me a little crazy. A vast majority of times (as in the example below) I have windows that really only contain one value at any given time. I never want to scroll. I never want lists. if I put a value in that windows I want it to overwrite the value that is already there. After looking at all the options I have chosen a listbox. Is that really my best option? Anyway..... I have been trying to get things to display in color and am having fits. It might somehow relate to the above side question. I have been using Melba23's example here: and can't get anything to display in the windows. Here is my code: <#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=SRT.ico #AutoIt3Wrapper_Res_Comment= #AutoIt3Wrapper_Res_Description= #AutoIt3Wrapper_Run_Au3Stripper=n #Au3Stripper_Parameters=/so #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** AutoItSetOption("MouseCoordMode", 1) ; 0=Relative to Active Window, 1=Absolute Screen 2=Relitive to Client Area AutoItSetOption("GUICloseOnESC", 1) ; Close on ESC #include-once Opt("TrayMenuMode", 1) #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <CommInterface.au3> #include <GuiListBox.au3> #include <Date.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <File.au3> #include <GuiRichEdit.au3> #Region ### START Koda GUI section ### Form=c:\users\jimbecher\desktop\idem v2.10\koda_1.7.2.0\forms\efdeck.kxf $EFDeck = GUICreate("EF Deck Display", 755, 248, 1001, 271) $EFDAvgTemp1 = _GUICtrlRichEdit_Create ($EFDeck,"", 184, 24, 57, 19) $EFDAvgTemp2 = _GUICtrlRichEdit_Create ($EFDeck,"", 184, 112, 57, 19) $EFDAvgTemp3 = _GUICtrlRichEdit_Create ($EFDeck,"", 184, 200, 57, 19) $EFDLimit1 = _GUICtrlRichEdit_Create ($EFDeck,"", 328, 24, 57, 19) $EFDLimit2 = _GUICtrlRichEdit_Create ($EFDeck,"", 328, 112, 57, 19) $EFDLimit3 = _GUICtrlRichEdit_Create ($EFDeck,"", 328, 200, 57, 19) $EFDExceeded1 = _GUICtrlRichEdit_Create ($EFDeck,"", 528, 24, 17, 19) $EFDExceeded2 = _GUICtrlRichEdit_Create ($EFDeck,"", 529, 112, 15, 19) $EFDExceeded3 = _GUICtrlRichEdit_Create ($EFDeck,"", 528, 200, 17, 19) $EFDReadings1 = _GUICtrlRichEdit_Create ($EFDeck,"", 672, 24, 57, 19) $EFDReadings2 = _GUICtrlRichEdit_Create ($EFDeck,"", 672, 112, 57, 19) $EFDReadings3 = _GUICtrlRichEdit_Create ($EFDeck,"", 672, 192, 57, 19) $Label2 = GUICtrlCreateLabel("Limit Exceeded:", 448, 24, 79, 17) $Label1 = GUICtrlCreateLabel(" 3 Hr Avg Temp:", 104, 24, 82, 17) $Label3 = GUICtrlCreateLabel("Readings:", 616, 24, 52, 17) $Label5 = GUICtrlCreateLabel("Baghouse 1", 32, 24, 61, 17) $Label9 = GUICtrlCreateLabel("3 Hr Avg Temp:", 104, 112, 79, 17) $Label10 = GUICtrlCreateLabel("Limit Exceeded:", 448, 112, 79, 17) $Label11 = GUICtrlCreateLabel("Readings:", 616, 112, 52, 17) $Label13 = GUICtrlCreateLabel("Baghouse 2", 32, 112, 61, 17) $Label17 = GUICtrlCreateLabel("3 Hr Avg Temp:", 104, 200, 79, 17) $Label18 = GUICtrlCreateLabel("Limit Exceeded:", 440, 200, 79, 17) $Label19 = GUICtrlCreateLabel("Readings:", 616, 192, 52, 17) $Label21 = GUICtrlCreateLabel("Baghouse 3", 32, 200, 61, 17) $Label37 = GUICtrlCreateLabel("Limit: ", 296, 24, 31, 17) $Label38 = GUICtrlCreateLabel("Limit:", 296, 112, 28, 17) $Label39 = GUICtrlCreateLabel("Limit", 296, 200, 25, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ColorWrite($EFDLimit1, 1 & @CRLF, -6, "", 0x000000) ColorWrite($EFDLimit2, 2 & @CRLF, -6, "", 0x000000) ColorWrite($EFDLimit3, 3 & @CRLF, -6, "", 0x000000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func ColorWrite($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1) ; Count the @CRLFs StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended ; Adjust the text char count to account for the @CRLFs Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines ; Add new text _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF) ; Select text between old and new end points _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1) ; Convert colour from RGB to BGR $iColor = Hex($iColor, 6) $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2) ; Set colour If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor) ; Set size If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement) ; Set weight If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib) ; Clear selection _GUICtrlRichEdit_Deselect($hWnd) EndFunc >
  4. Hi all, I want to show a color dialog box to user from my script. Is it possible ? I searched in help file but can't find anything related to a color dialog.
  5. hello Im wondering if it is possible to process image in autoit like this 1. firstly there is colorfull wallpaper 2. Fill all colors (exception rose color) - with white 3. Fill rose color with black color I see Gdi functions have things to manipulate images https://imgur.com/a/lFdY26g
  6. Im wondering if its possible to read pixel colors from not only from top window. For example I got a few windows with images how (in attachment video) . Is it possible to read pixel color for example 200px, 200px from top left ? Can i make something like winlist for the same window names and then get handles for every listed exact name window and then read for every window pixel color for example: 200px, 200px from top left ? https://streamable.com/l3pit 2018-12-10 01-02-38.mp4
  7. I want to create a slider that has values representing colors, like the slider on the _ChooseColor() GUI in the Misc.au3 UDF, but the max value for a slider is 32767. Here is my test code: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SliderConstants.au3> #include <Misc.au3> $hGUI = GUICreate("Test", 100, 560) $BtnID = GUICtrlCreateButton("Choose", 10, 10, 50, 25) ;~ GUICtrlSetOnEvent($BtnID, "handle_choose_btn") $flags = BitOR($TBS_AUTOTICKS, $TBS_VERT) $iSliderID = GUICtrlCreateSlider(10, 50, 40, 420, $flags) $hSlider_hWnd = GUICtrlGetHandle($iSliderID) $iMaxVal = 32767 GUICtrlSetLimit($iSliderID, $iMaxVal, 0) ; change min/max value GUISetState() GUIRegisterMsg($WM_VSCROLL, "WM_V_Slider") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP ToolTip("") case $BtnID handle_choose_btn() EndSwitch WEnd ; React to a slider movement Func WM_V_Slider($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam If $lParam = $hSlider_hWnd Then $iValue = GUICtrlRead($iSliderID) ConsoleWrite("+++: $iValue = " & $iValue & @CRLF) ToolTip(getRGB($iValue)) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_V_Slider ; Extract the RGB components from the color value Func getRGB($iColorVal) Local $hexstr, $b, $g, $r, $rgb $hexstr = StringFormat("%06X", $iColorVal) $r = StringMid($hexstr, 1, 2) $g = StringMid($hexstr, 3, 2) $b = StringMid($hexstr, 5, 2) $rgb = StringFormat("" & $iColorVal & " - rgb: %02s %02s %02s", $r, $g, $b) Return ($rgb) EndFunc ;==>getRGB Func handle_choose_btn() $color = _ChooseColor(2, 255, 0, $hGUI) ConsoleWrite("+++: $color = " & Hex($color, 8) & @CRLF) EndFunc ;==>handle_choose_btn
  8. Hey Community, I was changing around my color scheme manually for syntax highlighting. I really enjoy using a dark background color. However, this seems to be problematic because my blinking cursor is also very dark. Is there a setting in the ScITE config where I can manipulate the blinking cursor to be a different color like "white" so it is easy to spot when coding. The closest thing I found was "Caret Line Color", but this just changes the line highlight. Your help is greatly appreciated!!
  9. Hi all, fine? i need a little help! I need to get an array with the colors of the cells in the specified range! i've tried this, but don't work! Local $aCellColors = $oWorkbook.ActiveSheet.Usedrange.Columns("BK:BP").ColorIndex MsgBox(0,'',IsArray($aCellColors)) anyone help me? thanks a lot!
  10. 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
×
×
  • Create New...