|
@@ -42,9 +42,23 @@ def generate_random_colour():
|
|
|
logger.debug(f"Generated random colour: {colour}")
|
|
logger.debug(f"Generated random colour: {colour}")
|
|
|
return colour
|
|
return colour
|
|
|
|
|
|
|
|
|
|
+
|
|
|
"""
|
|
"""
|
|
|
-Karel functions
|
|
|
|
|
|
|
+Asset functions
|
|
|
"""
|
|
"""
|
|
|
|
|
+# Draw a background with random colour on the canvas
|
|
|
|
|
+def generate_random_background(canvas):
|
|
|
|
|
+ background = canvas.create_rectangle(
|
|
|
|
|
+ 1,
|
|
|
|
|
+ 1,
|
|
|
|
|
+ canvas.width,
|
|
|
|
|
+ canvas.height,
|
|
|
|
|
+ generate_random_colour(),
|
|
|
|
|
+ generate_random_colour()
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ return background
|
|
|
|
|
+
|
|
|
# Erase a passed Karel from the canvas
|
|
# Erase a passed Karel from the canvas
|
|
|
def erase_asset(asset):
|
|
def erase_asset(asset):
|
|
|
canvas = asset[1][0]
|
|
canvas = asset[1][0]
|
|
@@ -64,7 +78,7 @@ def move_karel(canvas, karel, x, y):
|
|
|
canvas.move(shape, x, y)
|
|
canvas.move(shape, x, y)
|
|
|
logger.debug(f"Moved: {karel} by {x} horizontally, {y} vertically")
|
|
logger.debug(f"Moved: {karel} by {x} horizontally, {y} vertically")
|
|
|
"""
|
|
"""
|
|
|
-# Move a passed Karel relative to previous position
|
|
|
|
|
|
|
+# Move a passed asset relative to previous position
|
|
|
def relative_move_asset(asset, x:int=0, y:int=0):
|
|
def relative_move_asset(asset, x:int=0, y:int=0):
|
|
|
# Update coordinates in list
|
|
# Update coordinates in list
|
|
|
asset[1][1] += x
|
|
asset[1][1] += x
|
|
@@ -77,7 +91,7 @@ def relative_move_asset(asset, x:int=0, y:int=0):
|
|
|
logger.debug(f"Moved {asset} by {x} horizontally, {y} vertically, to {new_asset}")
|
|
logger.debug(f"Moved {asset} by {x} horizontally, {y} vertically, to {new_asset}")
|
|
|
return new_asset
|
|
return new_asset
|
|
|
|
|
|
|
|
-# Move a passed Karel in relation to her orientation
|
|
|
|
|
|
|
+# Move a passed asset in relation to her orientation
|
|
|
def orientation_move_asset(asset, direction, amount):
|
|
def orientation_move_asset(asset, direction, amount):
|
|
|
# Direction translation
|
|
# Direction translation
|
|
|
# East
|
|
# East
|
|
@@ -131,7 +145,7 @@ def orientation_move_asset(asset, direction, amount):
|
|
|
logger.debug(f"Moved: {asset} {direction} by {amount} as {new_karel}")
|
|
logger.debug(f"Moved: {asset} {direction} by {amount} as {new_karel}")
|
|
|
return new_karel
|
|
return new_karel
|
|
|
|
|
|
|
|
-# Move a passed Karel to new coordinates
|
|
|
|
|
|
|
+# Move a passed asset to new coordinates
|
|
|
def absolute_move_asset(asset, x, y):
|
|
def absolute_move_asset(asset, x, y):
|
|
|
# Update coordinates in list
|
|
# Update coordinates in list
|
|
|
asset[1][1] = x
|
|
asset[1][1] = x
|
|
@@ -144,7 +158,7 @@ def absolute_move_asset(asset, x, y):
|
|
|
logger.debug(f"Moved: {asset} by {x} horizontally, {y} vertically, to {new_karel}")
|
|
logger.debug(f"Moved: {asset} by {x} horizontally, {y} vertically, to {new_karel}")
|
|
|
return new_karel
|
|
return new_karel
|
|
|
|
|
|
|
|
-# Change the orientation of a passed Karel
|
|
|
|
|
|
|
+# Change the orientation of a passed asset
|
|
|
def rotate_asset(asset, direction):
|
|
def rotate_asset(asset, direction):
|
|
|
# Relative turn
|
|
# Relative turn
|
|
|
if direction == "right" or direction == "left":
|
|
if direction == "right" or direction == "left":
|
|
@@ -211,7 +225,7 @@ def rotate_asset(asset, direction):
|
|
|
logger.debug(f"Rotated Karel: {asset} by {direction} as {asset[1][4]} to {new_karel}")
|
|
logger.debug(f"Rotated Karel: {asset} by {direction} as {asset[1][4]} to {new_karel}")
|
|
|
return new_karel
|
|
return new_karel
|
|
|
|
|
|
|
|
-# Recolour a passed Karel on the canvas
|
|
|
|
|
|
|
+# Recolour a passed asset on the canvas
|
|
|
"""
|
|
"""
|
|
|
Waiting for Stanford to fix a bug in the environment
|
|
Waiting for Stanford to fix a bug in the environment
|
|
|
CIP bug: https://codeinplace.stanford.edu/cip6/report?post=c36ed931-3019-4830-8ba6-655c1a513471
|
|
CIP bug: https://codeinplace.stanford.edu/cip6/report?post=c36ed931-3019-4830-8ba6-655c1a513471
|
|
@@ -249,6 +263,13 @@ def recolour_asset(asset, colour:str="black", background:str="white"):
|
|
|
logger.debug(f"Re-coloured Karel: {asset} with {colour} and {background} to {new_karel}")
|
|
logger.debug(f"Re-coloured Karel: {asset} with {colour} and {background} to {new_karel}")
|
|
|
return new_karel
|
|
return new_karel
|
|
|
|
|
|
|
|
|
|
+# Draw a random asset on the canvas
|
|
|
|
|
+def generate_random_asset(canvas):
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+"""
|
|
|
|
|
+Karel functions
|
|
|
|
|
+"""
|
|
|
# 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
|