Untitled
unknown
plain_text
3 months ago
972 B
13
Indexable
from turtle import *
from random import randint
t1 = Turtle()
t2 = Turtle()
def drawLines(t):
t.color('lightgray')
t.speed(50)
t.penup()
x = -200
y = 200
t.goto(x, y)
t.right(90)
t.pendown()
for i in range(20):
t.forward(400)
t.penup()
x += 20
t.goto(x, y)
t.pendown()
t.left(90)
def startRace(t, x, y, color):
t.color(color)
t.shape('turtle')
t.penup()
t.goto(x, y)
def dance(t):
t.speed(5)
t.penup()
t.goto(0, 0)
for i in range(20):
t.forward(i * 10)
t.right(90)
drawLines(t1)
startRace(t1, -200, -20, 'red')
startRace(t2, -200, 20, 'blue')
finish = 200
while t1.xcor() < finish and t2.xcor() < finish :
t1.forward(randint(2,7))
t2.forward(randint(2,7))
max_x = max(t1.xcor(), t2.xcor())
if t1.xcor() == max_x:
dance(t1)
if t2.xcor() == max_x:
dance(t2)
Editor is loading...
Leave a Comment