-
Notifications
You must be signed in to change notification settings - Fork 38
/
car.py
69 lines (57 loc) · 1.15 KB
/
car.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import turtle as t
# Create a turtle screen
screen = t.Screen()
screen.bgcolor("white")
# Create a turtle object for the car
car = t.Turtle()
car.shape("square")
car.color("blue")
# Function to draw a rectangle
def draw_rectangle(width, height, color):
car.color(color)
car.begin_fill()
for _ in range(2):
car.forward(width)
car.left(90)
car.forward(height)
car.left(90)
car.end_fill()
# Function to draw a circle
def draw_circle(radius, color):
car.penup()
car.color(color)
car.pendown()
car.begin_fill()
car.circle(radius)
car.end_fill()
car.penup()
car.pendown()
# Draw the car body
draw_rectangle(200, 50, "blue")
# Draw the windows
car.penup()
car.goto(50, 0)
car.pendown()
draw_rectangle(100, 30, "black")
# Draw the roof
car.penup()
car.goto(30, 50)
car.pendown()
draw_rectangle(140, 20, "blue")
# Draw the wheels
car.penup()
car.goto(40, -10)
car.pendown()
draw_circle(20, "black")
car.penup()
car.goto(160, -10)
car.pendown()
draw_circle(20, "black")
# Position the car
car.penup()
car.goto(0, -10)
car.pendown()
# Hide the turtle
car.hideturtle()
# Keep the window open
t.done()