返回顶部

一缕半夏微光

温柔半两,从容一生

导航

Python(小人发射爱心)

效果:

代码:

 1 from turtle import *
 2 
 3 def go_to(x, y):
 4     up()
 5     goto(x, y)
 6     down()
 7 
 8 def head(x, y, r):
 9     go_to(x, y)
10     speed(1)
11     circle(r)
12     leg(x, y)
13 
14 def leg(x, y):
15     right(90)
16     forward(180)
17     right(30)
18     forward(100)
19     left(120)
20     go_to(x, y - 180)
21     forward(100)
22     right(120)
23     forward(100)
24     left(120)
25     hand(x, y)
26 
27 def hand(x, y):
28     go_to(x, y - 60)
29     forward(100)
30     left(60)
31     forward(100)
32     go_to(x, y - 90)
33     right(60)
34     forward(100)
35     right(60)
36     forward(100)
37     left(60)
38     eye(x, y)
39 
40 def eye(x, y):
41     go_to(x - 50, y + 130)
42     right(90)
43     forward(50)
44     go_to(x + 40, y + 130)
45     forward(50)
46     left(90)
47 
48 def big_Circle(size):
49     speed(20)
50     for i in range(150):
51         forward(size)
52         right(0.3)
53 
54 def line(size):
55     speed(1)
56     forward(51 * size)
57 
58 def small_Circle(size):
59     speed(10)
60     for i in range(210):
61         forward(size)
62         right(0.786)
63 
64 def heart(x, y, size):
65     go_to(x, y)
66     left(150)
67     begin_fill()
68     line(size)
69     big_Circle(size)
70     small_Circle(size)
71     left(120)
72     small_Circle(size)
73     big_Circle(size)
74     line(size)
75     end_fill()
76 
77 def main():
78     pensize(2)
79     color('red', 'pink')
80     head(-120, 100, 100)
81     heart(250, -80, 1)
82     go_to(200, -300)
83     write("To: 李凯", move=True, align="left", font=("楷体", 20, "normal"))
84     done()
85 
86 main()

参考链接:使用Python画出小人发射爱心的代码

posted on 2021-12-10 16:24  一缕半夏微光  阅读(2038)  评论(0编辑  收藏  举报