-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors_and_shapes.py
57 lines (46 loc) · 1.01 KB
/
colors_and_shapes.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
#Write a python program to draw a 2d turtle graphics colors and shapes components.
import turtle
# Create a turtle screen
screen = turtle.Screen()
screen.bgcolor("lightblue")
# Create a turtle object
t = turtle.Turtle()
# Set the turtle speed
t.speed(2)
# Function to draw a square
def draw_square(color, size):
t.color(color)
t.begin_fill()
for _ in range(4):
t.forward(size)
t.left(90)
t.end_fill()
# Function to draw a circle
def draw_circle(color, radius):
t.color(color)
t.begin_fill()
t.circle(radius)
t.end_fill()
# Function to draw a triangle
def draw_triangle(color, size):
t.color(color)
t.begin_fill()
for _ in range(3):
t.forward(size)
t.left(120)
t.end_fill()
# Draw shapes
t.penup()
t.goto(-100, 0)
t.pendown()
draw_square("red", 100)
t.penup()
t.goto(60, 0)
t.pendown()
draw_circle("green", 50)
t.penup()
t.goto(100, 0)
t.pendown()
draw_triangle("blue", 100)
# Close the turtle graphics window when clicked
screen.exitonclick()