Jump to content
Macro Express Forums

Detecting Color Change


Recommended Posts

Hello. I know this question has been asked/answered a thousand times on these forums, but my situation is a bit different.


I play a game called EVE oline, and when I'm mining in space I want an alarm to sound when my cargo hold gets full of ore. I originally though ths would be very easy, I just have to check a pixel at the end of my cargo hold capacity bar. When it changes to orange, ring the bell.


However, it was isn't so easy, because not only does this bar have a gradient and a shading, it's also semi transparent. So that means that if my camera angle is over a diferent colored portion of the background, then color will change to a different shade.


Any ideas how I can over come this?

Link to comment
Share on other sites

Ah, looking for a change of colors won't work because if the background changes so will my color. For instance my mining laser will fire every second or so, and change the background, and thus the color of the capacity bar.


As for looking for a range of colors, I think that is the way to go. An earlier attempt had me doing a 5x5 pixel search and write 25 pixel colors in to a text file multiple times, in different circumstances. Then I'd check the pixels on the screen against the colors in the text file.


Not only was this pretty inellegant and slow, ther are also a lot of colors, such as shades of white and black that are present regardless of when the cargo bar is either orange (when she is full) or blue (when she is empty).


So maybe I have to some how search for a whole set of orange shades at the end of the cargo bar ...

Link to comment
Share on other sites

Yes, thats the solution ...


I want to check a single pixel and see if it is a shade of orange. I should be able to do this by writing the result of a get pixel command in the variable and then deconstructing it to see if it has the elements that would make it orange.


But how do i tell if some random 1 to 8 digit number that this function generates is orange or not?

Link to comment
Share on other sites

It sounds like you will need to have a basic understanding of how colors are created on your computer.


Each color on your computer is stored as 3 hexadecimal numbers in BGR format. BGR stands for Blue, Green and Red. Each hexadecimal number represents the amount of that color. So, for example, if the R value is 0 then there is no red. If the R value is FF then there is a lot of red and if the R value is 7F then there is 1/2 the available amount of red. Each hexadecimal number is combined into a color single value.


The hexadecimal values range from 00 through FF.


On my Windows XP desktop there is a cloudy blue sky. One of the blue colors has a pixel color of EE763B. This means there is EE Red, 76 Green, and 3B Red.


Macro Express does not have direct support for hexadecimal numbers. The Get Pixel Color/ command returns a single integer value. For the color EE763B the integer value returned is 15627835. You can use the Calculator in Windows to convert the hexadecimal value of EE763B into an integer and back to confirm this.


Knowing this you could write a macro that evaluates colors. But since Macro Express does not directly support hexadecimal numbers you will have to write some routines to do hexadecimal math.


I didn't say it was easy, just that it could be done. ;)

Link to comment
Share on other sites

Update: Here is where I stand.


I can convert the decimal number to hexadecimal with a pen and paper by repeatedly deviding the number/solution by 16 and recording the remainder.


But how do I convert this into code?


15627835/16 = 976739r11 B

976739/16 = 61046r3

61046/16 = 3815r6

3815/16 = 238r7

238/16 = 14r14 E

14/16 = 0r14 E


15627835dec = EE763Bhex!

Link to comment
Share on other sites

The Windows calculator. You can do all sorts of great things with it. Almost every key has an equivalent keyboard command. You can cut, paste, and copy from it to your clipboard. It works very well using Macro Express's Window Control commands.


In your case, its just a matter of switching it to hex mode, pasting a hex string into it, changing it back to decimals, and then copying from it to the clipboard.


And of course Macro Express can handle all of this.

Link to comment
Share on other sites

Here is a macro that will split the pixel color into the component parts of Red, Green and Blue.

// Get pixel color
Get Pixel: Under Mouse into %N10%
Variable Modify Integer: Copy %N10% to %N1%
Variable Modify Integer: Convert %N1% to decimal %D1%

// Get Red value
Variable Modify Decimal: %D1% = %D1% / 256
Variable Modify Decimal: Copy fraction part of %D1% to %D11%
Variable Modify Decimal: %D11% = %D11% * 256

// Get Green value
Variable Modify Decimal: Truncate %D1% to integer %N1%
Variable Modify Integer: Convert %N1% to decimal %D1%
Variable Modify Decimal: %D1% = %D1% / 256
Variable Modify Decimal: Copy fraction part of %D1% to %D12%
Variable Modify Decimal: %D12% = %D12% * 256

// Get Blue value
Variable Modify Decimal: Truncate %D1% to integer %N1%
Variable Modify Integer: Convert %N1% to decimal %D13%

// Here:
//     D11 = Red
//     D12 = Green
//     D13 = Blue

Text Box Display: Result

Now you will need to figure out how to determine what range of values represent some shade of orange. Good luck. Let us know how it turns out. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...