from graphics import Canvas from karel_asset import * # https://git.h0v1n8.nl/Stanford/karel_asset from time import sleep CANVAS_WIDTH = 400 CANVAS_HEIGHT = 400 def main(): canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT) while True: # Loop forever background = generate_random_background(canvas) sleep(0.5) # Set up asset stack amount = random.randint(5, 10) # Pick random amount of assets stack = {} # Create stack dictionary for _ in range(amount): # Create the amount of assets asset = generate_random_asset(canvas, karel_prevelance=6, centre_x=int(CANVAS_WIDTH / 2), centre_y=int(CANVAS_HEIGHT / 2), size=0) # Generate asset delay = random.randint(0, int(canvas.width * 1)) # Set random delay of a maximum of two canvas widths speed = random.choice((1, 2, 3, 4, 5)) # Set random speed name = "karel_" + str(_) # Set dictionary key stack.update({name: [asset, delay, speed]}) # Append entry to dictionary # Slide assets for i in range(int(canvas.width * 1.5)): # Zoom for 1.5 canvas widths for key, value in stack.items(): # Loop over asset dictionary if value[1] < i: # If delay has passed asset = relative_resize_asset(value[0], size_difference=value[2]) # Resize the assset stack.update({key: [asset, value[1], value[2]]}) # Update the dictionary sleep(0.01) # Wait shortly so the sliding is not CPU speed based # Erase assets in asset stack for value in stack.values(): erase_asset(value[0]) # Erase background for in the next loop a new one will be created canvas.delete(background) if __name__ == '__main__': main()