1+ import turtle
2+ import time
3+ from turtle import mainloop , hideturtle
4+
5+
6+ def clear_all ():
7+ turtle .penup ()
8+ turtle .goto (0 , 0 )
9+ turtle .color ('white' )
10+ turtle .pensize (800 )
11+ turtle .pendown ()
12+ turtle .setheading (0 )
13+ turtle .fd (300 )
14+ turtle .bk (600 )
15+
16+
17+ # 重定位海龟的位置
18+ def go_to (x , y , state ):
19+ turtle .pendown () if state else turtle .penup ()
20+ turtle .goto (x , y )
21+
22+
23+ def draw_heart (size ):
24+ turtle .color ('red' , 'pink' )
25+ turtle .pensize (2 )
26+ turtle .pendown ()
27+ turtle .setheading (150 )
28+ turtle .begin_fill ()
29+ turtle .fd (size )
30+ turtle .circle (size * - 3.745 , 45 )
31+ turtle .circle (size * - 1.431 , 165 )
32+ turtle .left (120 )
33+ turtle .circle (size * - 1.431 , 165 )
34+ turtle .circle (size * - 3.745 , 45 )
35+ turtle .fd (size )
36+ turtle .end_fill ()
37+
38+
39+ # 画出发射爱心的小人
40+ def draw_people (x , y ):
41+ turtle .penup ()
42+ turtle .goto (x , y )
43+ turtle .pendown ()
44+ turtle .pensize (2 )
45+ turtle .color ('black' )
46+ turtle .setheading (0 )
47+ turtle .circle (60 , 360 )
48+ turtle .penup ()
49+ turtle .setheading (90 )
50+ turtle .fd (75 )
51+ turtle .setheading (180 )
52+ turtle .fd (20 )
53+ turtle .pensize (4 )
54+ turtle .pendown ()
55+ turtle .circle (2 , 360 )
56+ turtle .setheading (0 )
57+ turtle .penup ()
58+ turtle .fd (40 )
59+ turtle .pensize (4 )
60+ turtle .pendown ()
61+ turtle .circle (- 2 , 360 )
62+ turtle .penup ()
63+ turtle .goto (x , y )
64+ turtle .setheading (- 90 )
65+ turtle .pendown ()
66+ turtle .fd (20 )
67+ turtle .setheading (0 )
68+ turtle .fd (35 )
69+ turtle .setheading (60 )
70+ turtle .fd (10 )
71+ turtle .penup ()
72+ turtle .goto (x , y )
73+ turtle .setheading (- 90 )
74+ turtle .pendown ()
75+ turtle .fd (40 )
76+ turtle .setheading (0 )
77+ turtle .fd (35 )
78+ turtle .setheading (- 60 )
79+ turtle .fd (10 )
80+ turtle .penup ()
81+ turtle .goto (x , y )
82+ turtle .setheading (- 90 )
83+ turtle .pendown ()
84+ turtle .fd (60 )
85+ turtle .setheading (- 135 )
86+ turtle .fd (60 )
87+ turtle .bk (60 )
88+ turtle .setheading (- 45 )
89+ turtle .fd (30 )
90+ turtle .setheading (- 135 )
91+ turtle .fd (35 )
92+ turtle .penup ()
93+
94+
95+ # 绘制文字
96+ def draw_text (text , t_color , font_size , show_time ):
97+ turtle .penup ()
98+ turtle .goto (- 350 , 0 )
99+ turtle .color (t_color )
100+ turtle .write (text , font = ('宋体' , font_size , 'normal' ))
101+ time .sleep (show_time )
102+ clear_all ()
103+
104+
105+ # 爱心发射
106+ def draw_ ():
107+ turtle .speed (0 )
108+ draw_people (- 250 , 20 )
109+ turtle .penup ()
110+ turtle .goto (- 150 , - 30 )
111+ draw_heart (14 )
112+ turtle .penup ()
113+ turtle .goto (- 200 , - 200 )
114+ turtle .color ('pink' )
115+ turtle .write ('Biu~' , font = ('宋体' , 60 , 'normal' ))
116+ turtle .penup ()
117+ turtle .goto (- 20 , - 60 )
118+ draw_heart (25 )
119+ turtle .penup ()
120+ turtle .goto (- 70 , - 200 )
121+ turtle .color ('pink' )
122+ turtle .write ('Biu~' , font = ('宋体' , 60 , 'normal' ))
123+ turtle .penup ()
124+ turtle .goto (200 , - 100 )
125+ draw_heart (45 )
126+ turtle .penup ()
127+ turtle .goto (150 , - 200 )
128+ turtle .color ('pink' )
129+ turtle .write ('Biu~' , font = ('宋体' , 60 , 'normal' ))
130+ turtle .hideturtle ()
131+ time .sleep (3 )
132+
133+
134+ def main ():
135+ # 隐藏海龟
136+ hideturtle ()
137+ turtle .setup (900 , 500 )
138+
139+ draw_text ("Are You Readly?" , "black" , 60 , 0 )
140+ draw_text ("接下来" , "skyblue" , 60 , 0 )
141+ draw_text ("感谢你的出现,让我的日子这么甜!" , "pink" , 35 , 3 )
142+ draw_ ()
143+
144+ # 使用mainloop防止窗口卡死
145+
146+ mainloop ()
147+
148+ if __name__ == '__main__' :
149+
150+ main ()
0 commit comments