-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek07.py
More file actions
49 lines (37 loc) · 1.3 KB
/
week07.py
File metadata and controls
49 lines (37 loc) · 1.3 KB
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
# Week 7: Turtle Art Gallery (Turtle Basics)
# Goal: Learn basic turtle commands - forward, right, goto, penup/pendown
# This program draws three squares at different positions on the screen.
import turtle
# Setup the screen (canvas)
screen = turtle.Screen()
screen.title("Turtle Art Gallery")
# Create a turtle (the drawing pen)
t = turtle.Turtle()
t.speed(6) # Drawing speed: 1 (slow) to 10 (fast), 0 = instant
def draw_square(size):
"""
Draw a square with the given side length.
Args:
size: Length of each side of the square
"""
for _ in range(4): # A square has 4 sides
t.forward(size) # Move forward by 'size' pixels
t.right(90) # Turn right 90 degrees (square corner)
# Draw first square at center (0, 0)
draw_square(60)
# Move to a new position WITHOUT drawing a line
t.penup() # Lift the pen (stop drawing)
t.goto(120, 0) # Move to coordinates (120, 0)
t.pendown() # Put pen down (start drawing again)
# Draw second square at new position
draw_square(90)
# Move to another position
t.penup()
t.goto(-120, -80) # Coordinates can be negative (left/down from center)
t.pendown()
# Draw third square
draw_square(40)
# Hide the turtle cursor (cleaner look)
t.hideturtle()
# Keep window open until clicked (important!)
screen.mainloop()