Code: Select all
radius := 10 ;initialize radius to 10
angle := 0 ;initialize angle to 0 degrees
z::
Loop, 87 ;loop 87 times only (create 87 circles with radius 10,11,12,13,...97)
{
Loop, 360 ;test all possible angles in increments of 1 degree
{
theta := (3.1415/180)*angle ;convert angle to radians
x := round(108 + radius * Cos(theta)) ;calculate x, round the value of x because pixel coordinates are integers
y := round(521 - radius * Sin(theta)) ;calculate y, round the value of y because pixel coordinates are integers
PixelGetColor, color, %x%, %y%, Fast, 20 ;get the pixel color code at x,y
Tooltip %radius%
if (color = 0xFF0000) ;if the color is found, then print box with information
{
MsgBox "X is: ", %x% , "Y is: ", %y%, "The angle is: ", %angle%
Exit
}
angle++ ;increase angle by 1 degree
}
radius++ ;increase radius by 1
angle := 0 ;reset angle to 0 to start a new search from origin
}
MsgBox Pixel not found!
y = 515.122
The next loop sets theta = 37, so
y = 514.98
The next loop sets theta = 38, so
y = 514.84
the next loop sets theta = 39, so
y = 514.706
Do you think this is the reason why this code takes too long to run? The sin and cos do not change fast and pixel search is looking at the same coordinates over and over again. What is one way to modify this code so that I can make it fast?