Added avoidance and fixed some stuff
This commit is contained in:
parent
aee46cd9a4
commit
763373ab17
|
@ -13,3 +13,5 @@ rgb111-full.png
|
||||||
state-new.json
|
state-new.json
|
||||||
settings.json
|
settings.json
|
||||||
screenshots/
|
screenshots/
|
||||||
|
avoid.png
|
||||||
|
result.png
|
||||||
|
|
34
async-bot.py
34
async-bot.py
|
@ -19,6 +19,7 @@ class AsyncBotManager:
|
||||||
self.difference: dict[int, bool] = {}
|
self.difference: dict[int, bool] = {}
|
||||||
self._last_update = 0
|
self._last_update = 0
|
||||||
self._shutdown: bool = False
|
self._shutdown: bool = False
|
||||||
|
self.avoid: set[range] = set()
|
||||||
|
|
||||||
def put_text(self, x: int, y: int, text: str):
|
def put_text(self, x: int, y: int, text: str):
|
||||||
with Image.new("LA", (int(self.font.getlength(text) + 12), 16)) as im:
|
with Image.new("LA", (int(self.font.getlength(text) + 12), 16)) as im:
|
||||||
|
@ -37,6 +38,29 @@ class AsyncBotManager:
|
||||||
if a:
|
if a:
|
||||||
self.difference[x + ox + (y + oy) * 1000] = l > 0
|
self.difference[x + ox + (y + oy) * 1000] = l > 0
|
||||||
|
|
||||||
|
def add_avoid_rect(self, sx: int, sy: int, w: int, h: int):
|
||||||
|
for y in range(sy, sy + h):
|
||||||
|
ox = y * 1000
|
||||||
|
self.add_avoid_range(sx + ox, sx + w + ox)
|
||||||
|
|
||||||
|
def add_avoid_range(self, start: int, stop: int, step: int = 1):
|
||||||
|
self.avoid.add(range(start, stop, step))
|
||||||
|
|
||||||
|
def get_difference_image(self) -> Image.Image:
|
||||||
|
with Image.new("LA", (1000, 1000), 0) as im:
|
||||||
|
for index, expected in self.difference.items():
|
||||||
|
y, x = divmod(index, 1000)
|
||||||
|
im.putpixel((x, y), (255 if expected else 0, 255))
|
||||||
|
return im.copy()
|
||||||
|
|
||||||
|
def get_avoid_image(self) -> Image.Image:
|
||||||
|
with Image.new("RGB", (1000, 1000), (0, 255, 0)) as im:
|
||||||
|
for rng in self.avoid:
|
||||||
|
for index in rng:
|
||||||
|
y, x = divmod(index, 1000)
|
||||||
|
im.putpixel((x, y), (255, 0, 0))
|
||||||
|
return im.copy()
|
||||||
|
|
||||||
async def listener(self):
|
async def listener(self):
|
||||||
async with ClientSession() as http:
|
async with ClientSession() as http:
|
||||||
async with http.get(f"{self.base}/api/initial-state") as req:
|
async with http.get(f"{self.base}/api/initial-state") as req:
|
||||||
|
@ -58,7 +82,7 @@ class AsyncBotManager:
|
||||||
bits_on, bits_off, timestamp = data
|
bits_on, bits_off, timestamp = data
|
||||||
if timestamp < self._last_update:
|
if timestamp < self._last_update:
|
||||||
print("SKIPPING UPDATES: TOO OLD")
|
print("SKIPPING UPDATES: TOO OLD")
|
||||||
self._last_update: int = data["timestamp"]
|
self._last_update: int = timestamp
|
||||||
for ndx in bits_on:
|
for ndx in bits_on:
|
||||||
y, x = divmod(ndx, 1000)
|
y, x = divmod(ndx, 1000)
|
||||||
self.canvas.putpixel((x, y), 255)
|
self.canvas.putpixel((x, y), 255)
|
||||||
|
@ -102,6 +126,11 @@ async def amain():
|
||||||
|
|
||||||
async with AsyncBotManager() as mgr:
|
async with AsyncBotManager() as mgr:
|
||||||
mgr.font = ImageFont.truetype(settings["font"], 8)
|
mgr.font = ImageFont.truetype(settings["font"], 8)
|
||||||
|
for avoid in settings["avoid"]:
|
||||||
|
if avoid["type"] == "rect":
|
||||||
|
mgr.add_avoid_rect(avoid["x"], avoid["y"], avoid["w"], avoid["h"])
|
||||||
|
elif avoid["type"] == "range":
|
||||||
|
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"])
|
||||||
|
@ -139,6 +168,9 @@ async def amain():
|
||||||
(color >> i) & 1
|
(color >> i) & 1
|
||||||
) > 0
|
) > 0
|
||||||
|
|
||||||
|
mgr.get_difference_image().save("result.png")
|
||||||
|
mgr.get_avoid_image().save("avoid.png")
|
||||||
|
|
||||||
if n_proxies := len(settings["proxies"]):
|
if n_proxies := len(settings["proxies"]):
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
|
|
|
@ -2,9 +2,26 @@
|
||||||
"url": "https://onemillioncheckboxes.com",
|
"url": "https://onemillioncheckboxes.com",
|
||||||
"font": "./ic8x8u.ttf",
|
"font": "./ic8x8u.ttf",
|
||||||
"proxies": [
|
"proxies": [
|
||||||
|
|
||||||
],
|
],
|
||||||
"n_bots": 10,
|
"n_bots": 5,
|
||||||
|
"avoid": [
|
||||||
|
{
|
||||||
|
"type": "rect",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"w": 1000,
|
||||||
|
"h": 10,
|
||||||
|
"description": "Not ruining fun for normal users"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "rect",
|
||||||
|
"x": 732,
|
||||||
|
"y": 184,
|
||||||
|
"w": 231,
|
||||||
|
"h": 326,
|
||||||
|
"description": "The Bald Critic"
|
||||||
|
}
|
||||||
|
],
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "rgb111",
|
"type": "rgb111",
|
||||||
|
@ -38,7 +55,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"path": "./lawbymike.png",
|
"path": "./astley.png",
|
||||||
"x": 150,
|
"x": 150,
|
||||||
"y": 420
|
"y": 420
|
||||||
},
|
},
|
||||||
|
@ -47,6 +64,12 @@
|
||||||
"path": "./colon3.png",
|
"path": "./colon3.png",
|
||||||
"x": 333,
|
"x": 333,
|
||||||
"y": 333
|
"y": 333
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": "7H3 V01D C0N5UME5 U5 ALL",
|
||||||
|
"x": 32,
|
||||||
|
"y": 32
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue