Commit
·
8fa31fb
1
Parent(s):
b68fc7d
ensures that alpha is a (40, 40, 3) mask matching RGB shape
Browse files
app.py
CHANGED
@@ -193,6 +193,10 @@ def knn_path(start, targets, occ):
|
|
193 |
# ── Robot sprite/class -──────────────────────────────────────────────────
|
194 |
class Robot:
|
195 |
def __init__(self, sprite, speed=2000): # Declare the robot's physical stats and routing (position, speed, movement, path)
|
|
|
|
|
|
|
|
|
196 |
self.png = np.array(Image.open(sprite).convert("RGBA").resize((40,40)))
|
197 |
self.pos = [0,0]; self.speed=speed
|
198 |
def step(self, path):
|
@@ -464,9 +468,10 @@ def _pipeline(uid,img_path):
|
|
464 |
# robot
|
465 |
robot.step(path)
|
466 |
rx,ry=robot.pos; sp=robot.png
|
467 |
-
a=sp[
|
468 |
-
|
469 |
-
frame[ry:ry+40,rx:rx+40]
|
|
|
470 |
# collection check
|
471 |
for o in objs:
|
472 |
if not o["col"] and np.hypot(o["pos"][0]-rx,o["pos"][1]-ry)<=20:
|
|
|
193 |
# ── Robot sprite/class -──────────────────────────────────────────────────
|
194 |
class Robot:
|
195 |
def __init__(self, sprite, speed=2000): # Declare the robot's physical stats and routing (position, speed, movement, path)
|
196 |
+
img = Image.open(sprite).convert("RGBA").resize((40, 40))
|
197 |
+
self.png = np.array(img)
|
198 |
+
if self.png.shape[-1] != 4:
|
199 |
+
raise ValueError("Sprite image must have 4 channels (RGBA)")
|
200 |
self.png = np.array(Image.open(sprite).convert("RGBA").resize((40,40)))
|
201 |
self.pos = [0,0]; self.speed=speed
|
202 |
def step(self, path):
|
|
|
468 |
# robot
|
469 |
robot.step(path)
|
470 |
rx,ry=robot.pos; sp=robot.png
|
471 |
+
a = sp[:, :, 3] / 255.0 # alpha channel
|
472 |
+
a = np.stack([a]*3, axis=-1) # shape (40, 40, 3)
|
473 |
+
bgroi = frame[ry:ry+40, rx:rx+40]
|
474 |
+
frame[ry:ry+40, rx:rx+40] = (a * sp[:, :, :3] + (1 - a) * bgroi).astype(np.uint8)
|
475 |
# collection check
|
476 |
for o in objs:
|
477 |
if not o["col"] and np.hypot(o["pos"][0]-rx,o["pos"][1]-ry)<=20:
|