|
|
@@ -226,6 +226,21 @@ def recolour_asset(asset, colour:str="black", background:str="white"):
|
|
|
logger.debug(f"Re-coloured Karel: {asset} with {colour} and {background} to {new_karel}")
|
|
|
return new_karel
|
|
|
|
|
|
+ # Draw a random Karel on the canvas
|
|
|
+def generate_random_karel(canvas):
|
|
|
+ # Base the size on the shortest pane
|
|
|
+ if canvas.width < canvas.height:
|
|
|
+ size = random.randint(1, canvas.width)
|
|
|
+ else:
|
|
|
+ size = random.randint(1, canvas.height)
|
|
|
+
|
|
|
+ centre_x = random.randint(int(size / 2), int(canvas.width - size / 2))
|
|
|
+ centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
+ orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
|
+ transparent = random.choice((True, False))
|
|
|
+
|
|
|
+ return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
|
+
|
|
|
# Draw a Karel
|
|
|
def draw_karel(
|
|
|
canvas,
|