-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
98 lines (87 loc) · 2.39 KB
/
example.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import turtle as turtle
import sys
def draw_square(t, size, color):
t.begin_fill()
t.color(color)
for _ in range(4):
t.forward(size)
t.right(90)
t.end_fill()
def draw_creeper_face(t):
# Set up the drawing environment
t.speed(0)
t.penup()
t.goto(-150, 150) # Starting position for the face
# Draw the green background
t.pendown()
draw_square(t, 300, "green")
# Draw the eyes
eye_positions = [(-90, 90), (30, 90)]
t.color("black")
for pos in eye_positions:
t.penup()
t.goto(pos)
t.pendown()
draw_square(t, 60, "black")
# Draw the mouth
mouth_positions = [(-90, -30), (-30, -30), (-30, -90), (30, -30), (30, -90)]
for pos in mouth_positions:
t.penup()
t.goto(pos)
t.pendown()
draw_square(t, 60, "black")
def drawing():
t.speed(0)
t.penup()
t.goto(-150, 150)
# Draw green background
t.pendown()
t.color("green")
t.begin_fill()
for _ in range(4):
t.forward(300)
t.right(90)
t.end_fill()
# Draw eyes
eye_size = 60
eye_positions = [(-90, 90), (30, 90)]
t.color("black")
for pos in eye_positions:
t.penup()
t.goto(pos)
t.pendown()
t.begin_fill()
for _ in range(4):
t.forward(eye_size)
t.right(90)
t.end_fill()
# Draw mouth
mouth_positions = [(-90, -30), (-30, -30), (-30, -90), (30, -30), (30, -90)]
for pos in mouth_positions:
t.penup()
t.goto(pos)
t.pendown()
t.begin_fill()
for _ in range(4):
t.forward(eye_size)
t.right(90)
t.end_fill()
"""
#################
!!Don't touch the code below!!
Unless you want to uncomment the 'turtle.done()' line
#################
'turtle.done()' is used to keep the turtle graphics window open
Uncomment the line if you want to see the turtle graphics window
However, when judging your code, we don't want to see the turtle graphics window,
so we commented it
#################
"""
if __name__ == '__main__':
result_path = sys.argv[1] # Accept output path as a command-line argument
s = turtle.getscreen()
t = turtle.Turtle()
drawing()
canvas = s.getcanvas()
canvas.postscript(file=result_path)
# turtle.done() # Uncomment this line if you want to keep the turtle graphics window open