|
@@ -270,6 +270,35 @@ def generate_random_asset(canvas):
|
|
|
"""
|
|
"""
|
|
|
Karel functions
|
|
Karel functions
|
|
|
"""
|
|
"""
|
|
|
|
|
+# Draw a random Karel outside the canvas
|
|
|
|
|
+def generate_outofbounds_random_karel(canvas, side):
|
|
|
|
|
+ # 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)
|
|
|
|
|
+
|
|
|
|
|
+ # Generate random coordinates (Outside the canvas geometry)
|
|
|
|
|
+ match side:
|
|
|
|
|
+ case "left":
|
|
|
|
|
+ centre_x = int(0 - size / 2)
|
|
|
|
|
+ centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
|
|
+ case "top":
|
|
|
|
|
+ centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
|
|
+ centre_y = int(0 - size / 2)
|
|
|
|
|
+ case "right":
|
|
|
|
|
+ centre_x = int(0 + size / 2)
|
|
|
|
|
+ centre_y = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
|
|
+ case "bottom":
|
|
|
|
|
+ centre_x = random.randint(int(size / 2), int(canvas.height - size / 2))
|
|
|
|
|
+ centre_y = int(0 + size / 2)
|
|
|
|
|
+
|
|
|
|
|
+ # Generate random values
|
|
|
|
|
+ orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
|
|
|
+ transparent = random.choice((True, False, False))
|
|
|
|
|
+
|
|
|
|
|
+ return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
|
|
|
+
|
|
|
# Draw a random Karel on the canvas
|
|
# Draw a random Karel on the canvas
|
|
|
def generate_random_karel(canvas):
|
|
def generate_random_karel(canvas):
|
|
|
# Base the size on the shortest pane
|
|
# Base the size on the shortest pane
|
|
@@ -282,7 +311,7 @@ def generate_random_karel(canvas):
|
|
|
centre_x = random.randint(int(size / 2), int(canvas.width - size / 2))
|
|
centre_x = random.randint(int(size / 2), int(canvas.width - size / 2))
|
|
|
centre_y = random.randint(int(size / 2), int(canvas.height - 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"])
|
|
orientation = random.choice(["east", "east-flipped", "north", "north-flipped", "west", "west-flipped", "south", "south-flipped"])
|
|
|
- transparent = random.choice((True, False))
|
|
|
|
|
|
|
+ transparent = random.choice((True, False, False, False))
|
|
|
|
|
|
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)
|
|
|
|
|
|