소스 검색

+generate_outofbounds_random_karel

tBKwtWS 1 개월 전
부모
커밋
34629475e5
1개의 변경된 파일30개의 추가작업 그리고 1개의 파일을 삭제
  1. 30 1
      karel_asset.py

+ 30 - 1
karel_asset.py

@@ -270,6 +270,35 @@ def generate_random_asset(canvas):
 """
 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
 def generate_random_karel(canvas):
     # 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_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))
+    transparent = random.choice((True, False, False, False))
 
     return draw_karel(canvas, centre_x, centre_y, size, orientation, "random", "random", transparent)