Implemented avoidance and black'd it
This commit is contained in:
parent
763373ab17
commit
5f8cda7c8a
27
async-bot.py
27
async-bot.py
|
@ -35,8 +35,13 @@ class AsyncBotManager:
|
||||||
for y in range(im.height):
|
for y in range(im.height):
|
||||||
for x in range(im.width):
|
for x in range(im.width):
|
||||||
l, a = im.getpixel((x, y)) # type: ignore
|
l, a = im.getpixel((x, y)) # type: ignore
|
||||||
|
index = x + ox + (y + oy) * 1000
|
||||||
if a:
|
if a:
|
||||||
self.difference[x + ox + (y + oy) * 1000] = l > 0
|
self.put_index(index, l > 0)
|
||||||
|
|
||||||
|
def put_index(self, index: int, value: bool):
|
||||||
|
if not any([index in avoid for avoid in self.avoid]):
|
||||||
|
self.difference[index] = value
|
||||||
|
|
||||||
def add_avoid_rect(self, sx: int, sy: int, w: int, h: int):
|
def add_avoid_rect(self, sx: int, sy: int, w: int, h: int):
|
||||||
for y in range(sy, sy + h):
|
for y in range(sy, sy + h):
|
||||||
|
@ -128,9 +133,13 @@ async def amain():
|
||||||
mgr.font = ImageFont.truetype(settings["font"], 8)
|
mgr.font = ImageFont.truetype(settings["font"], 8)
|
||||||
for avoid in settings["avoid"]:
|
for avoid in settings["avoid"]:
|
||||||
if avoid["type"] == "rect":
|
if avoid["type"] == "rect":
|
||||||
mgr.add_avoid_rect(avoid["x"], avoid["y"], avoid["w"], avoid["h"])
|
mgr.add_avoid_rect(
|
||||||
|
avoid["x"], avoid["y"], avoid["w"], avoid["h"]
|
||||||
|
)
|
||||||
elif avoid["type"] == "range":
|
elif avoid["type"] == "range":
|
||||||
mgr.add_avoid_range(avoid["start"], avoid["stop"], avoid["step"])
|
mgr.add_avoid_range(
|
||||||
|
avoid["start"], avoid["stop"], avoid["step"]
|
||||||
|
)
|
||||||
for elem in settings["elements"]:
|
for elem in settings["elements"]:
|
||||||
if elem["type"] == "text":
|
if elem["type"] == "text":
|
||||||
mgr.put_text(elem["x"], elem["y"], elem["text"])
|
mgr.put_text(elem["x"], elem["y"], elem["text"])
|
||||||
|
@ -147,9 +156,9 @@ async def amain():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ndx_start = (x + ox + (y + oy) * 577) * 3
|
ndx_start = (x + ox + (y + oy) * 577) * 3
|
||||||
mgr.difference[ndx_start] = r > 128
|
mgr.put_index(ndx_start, r > 128)
|
||||||
mgr.difference[ndx_start + 1] = g > 128
|
mgr.put_index(ndx_start + 1, g > 128)
|
||||||
mgr.difference[ndx_start + 2] = b > 128
|
mgr.put_index(ndx_start + 2, b > 128)
|
||||||
elif elem["type"] == "rgb565":
|
elif elem["type"] == "rgb565":
|
||||||
ox, oy = elem["x"], elem["y"]
|
ox, oy = elem["x"], elem["y"]
|
||||||
with Image.open(elem["path"]).convert("RGBA") as im:
|
with Image.open(elem["path"]).convert("RGBA") as im:
|
||||||
|
@ -164,9 +173,9 @@ async def amain():
|
||||||
color |= b >> 3
|
color |= b >> 3
|
||||||
|
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
mgr.difference[ndx_start + i] = (
|
mgr.put_index(
|
||||||
(color >> i) & 1
|
ndx_start + i, ((color >> i) & 1) > 0
|
||||||
) > 0
|
)
|
||||||
|
|
||||||
mgr.get_difference_image().save("result.png")
|
mgr.get_difference_image().save("result.png")
|
||||||
mgr.get_avoid_image().save("avoid.png")
|
mgr.get_avoid_image().save("avoid.png")
|
||||||
|
|
Loading…
Reference in New Issue