Letraindusoir Posted August 5, 2021 Share Posted August 5, 2021 (edited) expandcollapse popup#include <Color.au3> Local $aColor = [ _ ["0x858585", "0x7A7A7A"], _ ["0x848484", "0x7B7B7B"], _ ["0x8470FF", "0x7B8F00"], _ ["0x838B8B", "0x7C7474"], _ ["0x838B83", "0x7C747C"], _ ["0x836FFF", "0x7C9000"], _ ["0x828282", "0x7D7D7D"], _ ["0x7FFFD4", "0x80002B"], _ ["0x7FFF00", "0x8000FF"]] Local $hGUI = GUICreate("Color", 300, 560) For $i = 0 To 8 ;If _lumin($aColor[$i][0], $aColor[$i][1]) > 100 And _light($aColor[$i][0], $aColor[$i][1]) > 100 Then GUICtrlCreateLabel($aColor[$i][0], 10, 10 + (25 * $i), 200, 20, 0x0200 + 0x01) GUICtrlSetColor(-1, $aColor[$i][0]) GUICtrlSetBkColor(-1, $aColor[$i][1]) ;EndIf Next For $i = 0 To 8 ;If _lumin($aColor[$i][0], $aColor[$i][1]) > 125 And _light($aColor[$i][0], $aColor[$i][1]) > 125 Then GUICtrlCreateLabel($aColor[$i][1], 10, 30 + (25 * ($i + 9)), 200, 20, 0x0200 + 0x01) GUICtrlSetColor(-1, $aColor[$i][1]) GUICtrlSetBkColor(-1, $aColor[$i][0]) ;EndIf Next GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case -3 ExitLoop EndSwitch WEnd Func _lumin($hexColora, $hexColorb) Local $Difa = (_ColorGetRed($hexColora) * 299 + _ColorGetGreen($hexColora) * 587 + _ColorGetBlue($hexColora) * 114) / 1000 Local $Difb = (_ColorGetRed($hexColorb) * 299 + _ColorGetGreen($hexColorb) * 587 + _ColorGetBlue($hexColorb) * 114) / 1000 Return Abs($Difb - $Difa) EndFunc ;==>_lumin Func _light($hexColora, $hexColorb) Local $dRed = Abs(_ColorGetRed($hexColora) - _ColorGetRed($hexColorb)) Local $dGrn = Abs(_ColorGetGreen($hexColora) - _ColorGetGreen($hexColorb)) Local $dBlu = Abs(_ColorGetBlue($hexColora) - _ColorGetBlue($hexColorb)) Return ($dRed + $dGrn + $dBlu) EndFunc ;==>_light The codes As shown in the above. The Result display As follows: How to screen out the more obvious color matching through contrast and brightness? Specifically, how much is the contrast and brightness difference set to? Edited August 5, 2021 by Letraindusoir Link to comment Share on other sites More sharing options...
Nine Posted August 5, 2021 Share Posted August 5, 2021 (edited) Not sure what you are asking help for, but this may help you. It calculates the contrast between 2 colors, and if it larger than 7:1, it is considered as a high contrast. (based on W3C) expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <Color.au3> ; see https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-procedure Local $c1 = 0xFFFF80 Local $c2 = 0x000000 GUICreate("Calculate color Contrast", 550, 400) GUICtrlCreateLabel("", 50, 50, 200, 200) GUICtrlSetBkColor(-1, $c1) GUICtrlCreateLabel("", 300, 50, 200, 200) GUICtrlSetBkColor(-1, $c2) Local $iContrast = ColorContrast($c1, $c2) GUICtrlCreateLabel(Round($iContrast, 3), 225, 280, 100, 30, $SS_CENTERIMAGE+$SS_CENTER) GUICtrlSetFont(-1, 20) GUICtrlCreateLabel(($iContrast >= 7 ? "High" : "Low") & " Contrast", 10, 320, 530, 35, $SS_CENTERIMAGE+$SS_CENTER) GUICtrlSetFont(-1, 24) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func ColorContrast($iC1, $iC2) Local $iL1 = RelativeLuminescence($iC1) Local $iL2 = RelativeLuminescence($iC2) Return $iL1 > $iL2 ? ($iL1+0.05)/($iL2+0.05) : ($iL2+0.05)/($iL1+0.05) EndFunc Func RelativeLuminescence($iColor) Local $aCol = _ColorGetRGB($iColor) Local $R = $aCol[0]/255, $G = $aCol[1]/255, $B = $aCol[2]/255 $R = $R <= 0.03928 ? $R /12.92 : (($R + 0.055)/1.055) ^ 2.4 $G = $G <= 0.03928 ? $G /12.92 : (($G + 0.055)/1.055) ^ 2.4 $B = $B <= 0.03928 ? $B /12.92 : (($B + 0.055)/1.055) ^ 2.4 Return 0.2126 * $R + 0.7152 * $G + 0.0722 * $B EndFunc Edited August 5, 2021 by Nine Musashi, JockoDundee and Letraindusoir 2 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Letraindusoir Posted August 5, 2021 Author Share Posted August 5, 2021 1 hour ago, Nine said: Not sure what you are asking help for, but this may help you. It calculates the contrast between 2 colors, and if it larger than 7:1, it is considered as a high contrast. (based on W3C) That is exactly the answer I want. Thanks for the help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now