Header Ads

Header ADS

Trurtle Race


Source code:


import turtle
import random
#track
turtle.color('magenta')
for step in range(14):
    turtle.write(step)
    turtle.right(90)
    
    turtle.penup()
    turtle.forward(10)
    
    for i in range(11):
        turtle.forward(10)
        turtle.penup() #for dottet track.plain track is too simple.
        turtle.forward(10)
        turtle.pendown()
        
    turtle.penup()
    turtle.backward(230)
    turtle.left(90)
    turtle.forward(20) #track

#one
one = turtle.Turtle()
one.color('red')
one.shape('turtle')

one.penup()
one.goto(-20,-50)
turtle.pendown()
#two
two = turtle.Turtle()
two.color('darkgreen')
two.shape('turtle')

two.penup()
two.goto(-20,-90)
turtle.pendown()
#three
three = turtle.Turtle()
three.color('gold')
three.shape('turtle')

three.penup()
three.goto(-20,-130)
turtle.pendown()

#four
four = turtle.Turtle()
four.color('magenta')
four.shape('turtle')

four.penup()
four.goto(-20,-170)
turtle.pendown()
for turn in range(95):
    one.forward(random.randint(1,5))
    two.forward(random.randint(1,5))
    three.forward(random.randint(1,5))
    four.forward(random.randint(1,5))
    
    
turtle.exitonclick()


Output:


No comments

Theme images by centauria. Powered by Blogger.