 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ecksphore
Joined: 21 Nov 2006 Posts: 48
|
Posted: Wed Aug 20, 2008 5:50 am Post subject: PixelGetColor - most efficient way of doing this? |
|
|
What is the most efficient way of doing this?
I have a starting point of 100, 100.
Then I have a bunch of locations relevant to 100, 100 (starting point). The locations are :
10, 10
20, 10
13, 8
15, 20
24, 10
How can I check these locations one by one - but reset the starting point 100, 100 before checking the next one?
Thanks! |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Wed Aug 20, 2008 7:20 am Post subject: |
|
|
| Quote: | | PixelGetColor - most efficient way of doing this? | Write a script? Btw, where is your script?? |
|
| Back to top |
|
 |
ecksphore
Joined: 21 Nov 2006 Posts: 48
|
Posted: Wed Aug 20, 2008 5:59 pm Post subject: |
|
|
seriously? I'm in need of help and that's your answer?
I don't have any code as of yet because I'm not sure what is the most effecient way of doing this. I was hoping somone could give me a small example to get me started in the right direction.
Last edited by ecksphore on Wed Aug 20, 2008 6:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 397 Location: Minnesota, USA
|
Posted: Wed Aug 20, 2008 6:00 pm Post subject: |
|
|
His point being, have you actually attempted to do this yourself? If so, post what you have so we can help you fix/improve it. If not, read the manual
PixelGetColor
Loop _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
ecksphore
Joined: 21 Nov 2006 Posts: 48
|
Posted: Thu Aug 21, 2008 1:09 am Post subject: |
|
|
Ok, here is what I have :
| Code: |
Start:
EnvAdd, X1, 100 ; Starting point
EnvAdd, Y1, 100 ; Starting point
Envadd, X, %X1%
EnvAdd, Y, %Y1%
EnvAdd, X, 10 ; first loc
EnvAdd, Y, 10 ; first loc
PixelGetColor, color, %X%, %Y%
If color <> 0xFFFFFF
{
X = 0
Y = 0
Envadd, X, %X1%
EnvAdd, Y, %Y1%
EnvAdd, X, 20 ; second loc
EnvAdd, Y, 10 ; second loc
PixelGetColor, color, %X%, %Y%
If color <> 0xFFFFFF
{
... Third loc and so on ...
This repeats 6 times checking 6 different locations
}
}
|
So as you can see, it's ugly as hell and the reason why I didn't give an example in the first place.
I've been messing with this all day and I'm no further ahead than I was last night.
Please (anyone) have a look at my first post and let me know how to properly do this. I just want to have a starting point location (and reference that starting point each time) and check 6 points relevant to that starting point.
I have over 500 locations to check and this needs to be done by the end of the week. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1496
|
Posted: Thu Aug 21, 2008 2:13 am Post subject: |
|
|
Here's a little something that may be more advanced, though it should illuminate more of what AHK is capable of.
| Code: | Start:
StartX := 100
StartY := 100
color := 0xFFFFFF
If ( PixelMatch( color, StartX, StartY)
&& PixelMatch( color, StartX+10, StartY+10)
&& PixelMatch( color, StartX+20, StartY+10)
&& PixelMatch( color, StartX+13, StartY+ 8)
&& PixelMatch( color, StartX+15, StartY+20)
&& PixelMatch( color, StartX+24, StartY+10) )
MsgBox All the pixels are white
else
MsgBox One of the pixels is not white
return
; the function below is a wrapper for PixelSearch and it is acceptable to
; use in an 'If' statement because non-zero values are regarded as 'true'
PixelMatch(color, X1 = "", Y1 = "", X2 = "", Y2 = "", variation = 0, options = "" )
{ ; function by [VxE]. Determines if a pixel of a certain color
; or an acceptable variation of that color can be found within
; the region. This function can also be used to determine whether
; a single pixel is a certain color or is within a variation.
; If the region parameters are left blank or non-numeric, the
; dimension of the screen is used. i.e. PixelMatch(0x000000)
; will return non-zero if there is a black pixel on the screen
X1 += 0, Y1 += 0, X2 += 0, Y2 += 0 ; robustness consideration
IfEqual, X2,, SetEnv, X2, % (X1="") ? A_ScreenWidth : X1
IfEqual, Y2,, SetEnv, Y2, % (Y1="") ? A_ScreenHeight : X1
IfEqual, X1,, SetEnv, X1, 0
IfEqual, Y1,, SetEnv, Y1, 0
PixelSearch, x, y, X1, Y1, X2, Y2, color, variation, options ; broken line, should be % signs in there
If !ErrorLevel
return ( ((x + 32768) << 16) | (y + 32768) ) ".01"
return 0
; The return value will be zero if the target color is not found in the
; specified region. The return value will be non-zero if it is found.
; the coordinates of the matching pixel found are encoded into the return
; value, use [FoundX := Value // 65536 - 32768]
; and [FoundY := Value & 65535 - 32768]
; to retreive the coordinates of a matching pixel.
}
/*
EnvAdd, X1, 100 ; Starting point
EnvAdd, Y1, 100 ; Starting point
Envadd, X, %X1%
EnvAdd, Y, %Y1%
EnvAdd, X, 10 ; first loc
EnvAdd, Y, 10 ; first loc
PixelGetColor, color, %X%, %Y%
If color <> 0xFFFFFF
{
X = 0
Y = 0
Envadd, X, %X1%
EnvAdd, Y, %Y1%
EnvAdd, X, 20 ; second loc
EnvAdd, Y, 10 ; second loc
PixelGetColor, color, %X%, %Y%
If color <> 0xFFFFFF
{
... Third loc and so on ...
This repeats 6 times checking 6 different locations
}
}
*/ |
_________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Last edited by [VxE] on Sat Aug 23, 2008 5:01 am; edited 1 time in total |
|
| Back to top |
|
 |
ecksphore
Joined: 21 Nov 2006 Posts: 48
|
Posted: Thu Aug 21, 2008 2:29 am Post subject: |
|
|
This is exactly what I was looking for!
Thank you!!  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|