[Turtle] Clash camera race with Python

Hello.
the Year-Round 410 Error
System Solutions Department.
The humidity, heat, and local taxes have been making me feel a bit down lately, so this time I use
turtle to make some turtles compete. As you can see in the GIF image above, there are a lot of things you can do, so please try moving your favorite turtles around as much as you like.
Operating environment and full code
So let's get started
Operating system: Microsoft Windows 10 Pro
Python version: 3.10
from turtle import * from random import randint import time #Draw a line for step in range(11): write(step, align='center') speed(80) right(90) forward(10) pendown() forward(150) penup() backward(160) left(90) forward(20) time.sleep(1) #Red turtle red = Turtle() red.color('red') red.shape('turtle') red.penup() red.goto(0, -10) #Blue turtle blue = Turtle() blue.color('blue') blue.shape('turtle') blue.penup() blue.goto(0, -30) #Yellow turtle yellow = Turtle() yellow.color('orange') yellow.shape('turtle') yellow.penup() yellow.goto(0, -60) #Green turtle green = Turtle() green.color('green') green.shape('turtle') green.penup() green.goto(0, -90) #black turtle black = Turtle() black.color('black') black.shape('turtle') black.penup() black.goto(0, 60) #mouse turtle gray = Turtle() gray.color('gray') gray.shape('turtle') gray.penup() gray.goto(0, -120) #rotating turtle pink = Turtle() pink.color('pink') pink.shape('turtle') pink.penup() pink.goto(0, -150) time.sleep(3) #move each turtle x100 for kame in range(100): red.forward(randint(1, 2)) blue.forward(randint(-1, 3)) yellow.forward(randint(-3, 4)) green.forward(randint(-4, 5)) black.right(90) gray.forward(randint(-3, -2)) pink.forward(randint(-10, 10))
Code explanation
Import each library.
The random time is just for making the turtle
wait a little after placing it, so it's fine if you don't add it.
from turtle import * from random import randint import time
Honestly, this is the only part you need to worry about.
Starting from 0, repeat with for until 10 lines are drawn as the racetrack.
for step in range(11): write(step, align='center') speed(80) right(90) forward(10) pendown() forward(150) penup() backward(160) left(90) forward(20)
Use color() to specify the color of the turtle.
* You can specify the color in more detail with
fillcolor() Use shape() to specify the shape of the turtle, and goto() to specify the initial coordinates. You can move the subsequent turtles little by little while debugging.
#Red turtle red = Turtle() red.color('red') red.shape('turtle') red.penup() red.goto(0, -10)
Use "for" to make it move 100 times
For each turtle, one of the numbers (number, number) is randomly selected
This timeIt's a painI didn't mention it here, but it would probably create a good atmosphere if they displayed something like "Goal!" when the goal was reached
for kame in range(100): red.forward(randint(1, 2)) blue.forward(randint(-1, 3)) yellow.forward(randint(-3, 4)) green.forward(randint(-4, 5)) black.right(90) gray.forward(randint(-3, -2)) pink.forward(randint(-10, 10))
Originally, turtlr was a drawing library, but with the inclusion of the turtle shape, it can also be used in this way.
(For detailed usage, please refer to
the official documentation
please try it out in a cool, air-conditioned room.
13