Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Pixelsearch outward from central location?

  • Please log in to reply
2 replies to this topic
  • Members
  • 13 posts
  • Last active: Dec 03 2015 11:17 PM
  • Joined: 29 Apr 2013

Im looking for a way to search for a pixel with the search starting in a central location and progressing out towards the search perimeter~

any suggestions?



  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012
✓  Best Answer

I suppose one way to do it would be to search from the central four pixels, and then the central sixteen, and then the central thirty-six, and so on. Not perfectly radial, as it's not a circle but a square we're doing here, but it's the only way I can think to do it without bringing in libraries and other codes. The code below may not do so hot once you go beyond the bounds of the smaller value (which is usually A_ScreenHeight); the script might detect black at those coordinates or fail completely, not sure.

PixelSearch, outputx, outputy, A_ScreenWidth/2-A_Index, A_ScreenHeight/2-A_Index, A_ScreenWidth/2+A_Index-1, A_ScreenHeight/2+A_Index-1, 0xFFFFFF
If !ErrorLevel ; the pixel was found
MouseMove, outputx, outputy

The mathsy part comes at A_ScreenWidth/2-A_Index, A_ScreenHeight/2-A_Index, A_ScreenWidth/2+A_Index-1, A_ScreenHeight/2+A_Index-1. A_Index is always increasing by one for each iteration of a loop.


Explanation of coming up with the coordinates below:




Hopefully I did my maths correct. The starting at zero threw me for a bit at first and my original code is now edited to correct for that.

  • Members
  • 13 posts
  • Last active: Dec 03 2015 11:17 PM
  • Joined: 29 Apr 2013

thats actually perfect, thanks a lot