Is it possible to find the x,y coordinates of a certain color on the screen? Or a perhaps a group with the same color and find the center of that? I tried using image:get(), but it only gets 1 pixel, so that doesn't work. Can anyone help me? Thanks in advance.
Comments
You could could use image:get() on each pixel I turn by using a couple of loops.
@Leviathan Actually r,g,b,a=image:get(x,y) does work. You just have to go thru all of the x,y values for that image to find the color you want.
@dave1707 Really? Wow, that's cool. But when I put Width/2 and Height/2 for height. It doesn't work. It only reads that pixel. So I'm still confused on what your saying. Can you give an example?
@Leviathan Here an example. This will print only 100 color values because there could be thousands.
@dave1707 hey thank you! I like how you used the break tool. Forgot about that in the old lua programmer on ios. Sweet thank you! This all makes sense.
You could also add a third parameter to skip over a few pixels in between, good for speeding things up. Using image.get can be very slow and make a noticable difference if you use it enough.
@Leviathan - if you want to find the whole filled area, you can use SkyTheCoder's suggestion to find the first pixel (assuming the colour only occurs in one place of course), and then use a recursive loop to find all the neighbouring cells with the same colour. I used one in this post (see the recursion part at bottom)
https://coolcodea.wordpress.com/2013/03/30/18-lessons-from-a-simple-board-game-part-1/
(NB in the code, Wordpress mangles > signs into > and < into <)
(It can be done more efficiently using a table, but I can't find my code for that right now).
@Ignatz I'll take a look at that, thank you!