import turtle
import random

wn = turtle.Screen()
wn.title("Turtle Race")
wn.bgcolor("darkgreen")
def title():
    turtle.speed(0)
    turtle.color("White")
    turtle.penup()
    turtle.goto(0,300)
    turtle.write("Turtle Race",align="center",font=("Avalon",50))
    turtle.hideturtle()
def yellow():

    yellow_rect = turtle.Turtle()
    yellow_rect.pencolor("yellow")
    yellow_rect.speed(0)
    yellow_rect.penup()
    yellow_rect.goto(-400,250)
    yellow_rect.pendown()
    yellow_rect.fillcolor("yellow")
    yellow_rect.begin_fill()
    yellow_rect.fd(800)
    yellow_rect.rt(90)
    yellow_rect.fd(500)
    yellow_rect.rt(90)
    yellow_rect.fd(800)
    yellow_rect.rt(90)
    yellow_rect.fd(500)
    yellow_rect.end_fill()
    yellow_rect.hideturtle()
def lines():
    pos_x = -360
    num = 1

    line = turtle.Turtle()
    line.speed(0)
    line.rt(90)
    for i in range(30):
        line.speed(0)
        line.penup()
        line.goto(pos_x, 230)
        line.write(num, align="center")
        line.fd(10)
        line.pendown()
        line.fd(460)
        line.hideturtle()
        pos_x += 22.5
        num += 1
def finish_line():
    pos_x = 330
    pos_y = 220
    finish = turtle.Turtle()

    def black():
        pos_x = 330
        pos_y = 220
        finish = turtle.Turtle()
        finish.speed(0)
        finish.penup()
        finish.goto(330,220)
        finish.pendown()
        for j in range(10):

            finish.fillcolor("black")
            finish.begin_fill()
            finish.fd(23)
            finish.rt(90)
            finish.fd(23)
            finish.lt(90)
            finish.fd(23)
            finish.rt(90)
            finish.fd(23)
            finish.rt(90)
            finish.fd(23)
            finish.rt(90)
            finish.fd(23)
            finish.lt(90)
            finish.fd(23)
            finish.rt(90)
            finish.fd(23)
            finish.rt(90)
            finish.penup()
            pos_y -= 46
            finish.goto(pos_x,pos_y)
            finish.pendown()
            finish.end_fill()
            finish.hideturtle()
    def white():
        finish.speed(0)
        finish.hideturtle()
        finish.penup()
        finish.goto(330,220)
        finish.pencolor("white")
        finish.fillcolor("white")
        finish.begin_fill()
        finish.fd(46)
        finish.rt(90)
        finish.fd(460.5)
        finish.rt(90)
        finish.fd(46)
        finish.rt(90)
        finish.fd(460.5)
        finish.rt(90)
        finish.end_fill()

    white()
    black()

def turtle_race():
    turtle.penup()
    t1 = turtle.Turtle()
    t1.penup()
    t1.fillcolor("blue")
    t1.goto(-390,128)
    t1.shape("turtle")
    t2 = turtle.Turtle()
    t2.penup()
    t2.fillcolor("red")
    t2.goto(-390,50)
    t2.shape("turtle")
    t3 = turtle.Turtle()
    t3.penup()
    t3.fillcolor("green")
    t3.goto(-390,-50)
    t3.shape("turtle")
    t4 = turtle.Turtle()
    t4.penup()
    t4.fillcolor("black")
    t4.goto(-390,-128)
    t4.shape("turtle")
    for i in range(37):
        t1.speed(random.randrange(0,11))
        t2.speed(random.randrange(0,11))
        t3.speed(random.randrange(0,11))
        t4.speed(random.randrange(0,11))
        t1.pendown()
        t2.pendown()
        t3.pendown()
        t4.pendown()
        t1.fd(20)
        t2.fd(20)
        t3.fd(20)
        t4.fd(20)

 

    t5 = turtle.exitonclick()


def main():
    title()
    yellow()
    lines()
    finish_line()
    turtle_race()
main()
    



