Sign in to follow this  
Followers 0
Lynie

Colors

16 posts in this topic

#1 ·  Posted (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 by Lynie

Share this post


Link to post
Share on other sites



Do you want to use this in a searchpixel funtion?

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Lynie

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#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.

Share this post


Link to post
Share on other sites

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

Yes 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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 :).

:lmao:

Edited by Lynie

Share this post


Link to post
Share on other sites

Solved. Thanks all!

Share this post


Link to post
Share on other sites

Your question just isn't clear enough. What do you consider base colors? Only red, blue, green?

Share this post


Link to post
Share on other sites

#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)

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Well you need to use a standard set of color keywords:

http://www.w3schools.com/HTML/html_colornames.asp

Well 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 by Lynie

Share this post


Link to post
Share on other sites

Right now I'm using this

Func 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?

Share this post


Link to post
Share on other sites

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)

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