# Allison Obourn
# CS 115, Autumn 2021
# Lecture 12

# This program opens a window that is wider than it is tall. This
# window has a gray background and contains a black car with red wheels
# and a cyan windsheild facing right. It drives along the panel until it
# is completely out of the window. Then it reappears on the left side. 

from ECGUI import *

# NOTE: you can tell this is a constant because it is at the top and the
#       name is in ALL_CAPS
PANEL_WIDTH = 260

# NOTE: this is a variable that changes so its name is lowercase
x = 10

panel = drawing_panel(PANEL_WIDTH, 120, "gray")


def repeat():
    panel.clear()
    global x   # so we can alter the x variable declare outside our function
    y = 30
    panel.fill_rect(x, y, 100, 50, "black")
    panel.fill_oval(x + 10, y + 40, 20, 20, "red")
    panel.fill_oval(x + 70, y + 40, 20, 20, "red")
    panel.fill_rect(x + 70, y + 10, 30, 20, "cyan")

    # check if we have driven completely off the screen and if we have
    # start back on the left
    # NOTE: this doesn't work quite right yet! We will fix it tomorrow
    if x >= PANEL_WIDTH:
        x = 0
    else:
        x = x + 2 # if we add a bigger number we will move faster

    # draws the road along the bottom
    panel.set_stroke(6)
    panel.draw_line(0, 95, PANEL_WIDTH, 95)
    

panel.animate(50, repeat)
