Lynie Posted January 20, 2009 Share Posted January 20, 2009 (edited) Hello Does anyone know how the decimal values of colors are formed? I'm asking this because I'm trying to create a function that compares the colors to see which one is the closest to a base color(or is there already a function that does this?). For example Darkgreen should be closer to green then it is to red, so the function should return green. Thanks EDIT: Made the example more clearly Edited January 20, 2009 by Lynie Link to comment Share on other sites More sharing options...
Zompy Posted January 20, 2009 Share Posted January 20, 2009 Do you want to use this in a searchpixel funtion? Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 (edited) Do you want to use this in a searchpixel funtion?No, as I said in my post, I want to compare colors(like the example) Edited January 20, 2009 by Lynie Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 20, 2009 Moderators Share Posted January 20, 2009 Lynie, Colours in AutoIt are usually in RGB format. That is a hex format 0x###### where the First 2 ## are the Red, next 2 the Green, final 2 the Blue (RGB - get it?). 0xFFFFFF = White, 0x000000 = Black, 0xFF0000 = Red, 0x00FF00 = Green, 0x0000FF = Blue, 0xFFFF00 = Yellow, etc. Any colour can be defined as a mix of these three components. The decimal value is just the Hex expressed as a decimal number. So White as decimal = Dec("FFFFFF") - (note the requirement to have the hex as a string and without the 0x). Does that answer the question? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Aceguy Posted January 20, 2009 Share Posted January 20, 2009 (edited) Use _ColorGetBlue($nColor) _ColorGetRed($nColor) _ColorGetGreen($nColor) Edited January 20, 2009 by Aceguy [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
Pain Posted January 20, 2009 Share Posted January 20, 2009 #include <Color.au3> $nColor = 0xFF4C1B $r = _ColorGetRed($nColor) $g = _ColorGetGreen($nColor) $b = _ColorGetBlue($nColor) ConsoleWrite($r &@CR & $g &@CR & $b & @CR) You get the point, then only return the largest one. Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 Lynie,Colours in AutoIt are usually in RGB format. That is a hex format 0x###### where the First 2 ## are the Red, next 2 the Green, final 2 the Blue (RGB - get it?). 0xFFFFFF = White, 0x000000 = Black, 0xFF0000 = Red, 0x00FF00 = Green, 0x0000FF = Blue, 0xFFFF00 = Yellow, etc.Any colour can be defined as a mix of these three components. The decimal value is just the Hex expressed as a decimal number. So White as decimal = Dec("FFFFFF") - (note the requirement to have the hex as a string and without the 0x).Does that answer the question?M23Yes it does. Thanks.But do you have a theory for the function I described in the example. I was thinking about creating an array for all the characters that come in the hex and then comparing each char of the hex string to it. But it's going to be hard. So any help? Thanks. Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 (edited) Use _ColorGetBlue($nColor) _ColorGetRed($nColor) _ColorGetGreen($nColor) #include <Color.au3> $nColor = 0xFF4C1B $r = _ColorGetRed($nColor) $g = _ColorGetGreen($nColor) $b = _ColorGetBlue($nColor) ConsoleWrite($r &@CR & $g &@CR & $b & @CR) You get the point, then only return the largest one. Thanks both. You completly solved it . Edited January 20, 2009 by Lynie Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 Solved. Thanks all! Link to comment Share on other sites More sharing options...
weaponx Posted January 20, 2009 Share Posted January 20, 2009 Your question just isn't clear enough. What do you consider base colors? Only red, blue, green? Link to comment Share on other sites More sharing options...
Aceguy Posted January 20, 2009 Share Posted January 20, 2009 #include <color.au3> #include<array.au3> dim $col[4] $Test_color=8062258 $col[1]=_ColorGetBlue($Test_color) $col[2]=_ColorGetRed($Test_color) $col[3]=_ColorGetGreen($Test_color) $ret=_ArrayMinIndex($col,1,1,3) if $ret=1 then MsgBox(0,"","The closest colour is Blu ",0) if $ret=2 then MsgBox(0,"","The closest colour is Red",0) if $ret=3 then MsgBox(0,"","The closest colour is Green",0) [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 Well no, that's why I'm acutally posting this again. What if I want to check for combination of colors? Like white, purple, etc... (Sorry :s) Link to comment Share on other sites More sharing options...
weaponx Posted January 20, 2009 Share Posted January 20, 2009 Well no, that's why I'm acutally posting this again. What if I want to check for combination of colors?Like white, purple, etc...(Sorry :s)Well you need to use a standard set of color keywords:http://www.w3schools.com/HTML/html_colornames.asp Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 (edited) Well you need to use a standard set of color keywords:http://www.w3schools.com/HTML/html_colornames.aspWell see the problem is I'm scanning for colors in a gameboard and the program I'm creating copies the colors into the GUI. But you'll notice the colors in the GUI slightly change each time(because the colors in the gameboard have some kind of mapping(shades, bright spots, etc...). And that's why I want to replace it with the best suiting (correct) color Edited January 20, 2009 by Lynie Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 Right now I'm using this expandcollapse popupFunc GetCorrectColor($color) $temp = $color $gcolor = Hex($temp) $red = @CR & _ColorGetRed($color) $green = @CR & _ColorGetGreen($color) $blue = @CR & _ColorGetBlue($color) If($red > $green And $red > $blue) Then $gColor = 0xFF0000 EndIf If($green> $red And $green > $blue) Then $gColor = 0x00FF00 EndIf If($blue > $green And $blue > $red) Then $gColor = 0x0000FF EndIf If($red > 210 And $green > 210 And $blue > 210) Then;white $gColor = 0xFFFFFF EndIf If($red > 210 And $green > 170 And $green < 220 And $blue > 210) Then;purple $gColor = 0xebbad7 EndIf If($red > 230 And $green > 125) Then;orange $gColor = 0xef8128 EndIf If($red > 210 And $green > 200) Then;yellow $gColor = 0xffd61a EndIf MsgBox(64, $WINDOWTITLE, "R:" & $red & " G:" & $green & " B:" & $blue) Return $gColor EndFunc As you can see I put a msgbox reporting every tile's color before returning it, however I checked this code by looking at the RGB(R:241 G:49 B:26) of the first tile and checking every if condition and it should return 0xFF0000, but the GUI tile turns green, so what am I doing wrong? Link to comment Share on other sites More sharing options...
Lynie Posted January 20, 2009 Author Share Posted January 20, 2009 I've figured out the problem! Now it just a mather of make the function more precise cause it kind of works just not always the right colors. For those intrested I changed $red = @CR & _ColorGetRed($color) $green = @CR & _ColorGetGreen($color) $blue = @CR & _ColorGetBlue($color) Into $red = _ColorGetRed($color) $green = _ColorGetGreen($color) $blue = _ColorGetBlue($color) 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