File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ """
4+ @author: 闲欢
5+ """
6+
7+ import turtle as tur
8+
9+
10+ # 爱心函数
11+ # r为半圆半径,l = 2r为正方形边长
12+ # 调整半径即可调整爱心大小
13+ def loving_heart (r ):
14+ l = 2 * r
15+ tur .left (45 )
16+ tur .forward (l )
17+ tur .circle (r , 180 )
18+ tur .right (90 )
19+ tur .circle (r , 180 )
20+ tur .forward (l )
21+
22+
23+ # 树函数(递归)
24+ def tree (d , s ):
25+ if d <= 0 :
26+ return
27+ tur .forward (s )
28+ tree (d - 1 , s * .8 )
29+ tur .right (120 )
30+ tree (d - 3 , s * .5 )
31+ tur .right (120 )
32+ tree (d - 3 , s * .5 )
33+ tur .right (120 )
34+ # 回退函数
35+ tur .backward (s )
36+
37+
38+ # 画爱心部分
39+ tur .penup ()
40+ # 设置起点位置
41+ tur .goto (0 , 200 )
42+ tur .pendown ()
43+ # 设置画笔颜色
44+ tur .pencolor ('pink' )
45+ tur .color ('pink' )
46+ # 对图形进行填充
47+ tur .begin_fill ()
48+ # 执行画爱心函数
49+ loving_heart (20 )
50+ tur .end_fill ()
51+
52+ # 画树部分
53+ n = 100
54+ tur .speed ('fastest' )
55+ tur .right (225 )
56+ tur .color ("dark green" )
57+ tur .backward (n * 4.8 )
58+ tree (15 , n )
59+ tur .backward (n / 5 )
60+ tur .penup ()
61+ tur .Turtle ().screen .delay (2 )
62+ tur .goto (80 , 0 )
63+ tur .pendown ()
64+ tur .color ("gold" )
65+ tur .write ("Merry Christmas!" , font = ("Times" , 32 , "bold" ))
66+ tur .hideturtle ()
You can’t perform that action at this time.
0 commit comments