Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson9_4
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3def2763
authored
Mar 15, 2025
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
62692a77
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
0 deletions
2-9-diy5.py
sd.py
2-9-diy5.py
0 → 100644
View file @
3def2763
import
turtle
import
math
# 设置画布和画笔
screen
=
turtle
.
Screen
()
t
=
turtle
.
Turtle
()
t
.
speed
(
0
)
# 设置画笔速度
# 定义绘制圣诞树的函数
def
draw_tree
(
branch_len
):
if
branch_len
>
5
:
t
.
forward
(
branch_len
)
t
.
right
(
20
)
draw_tree
(
branch_len
-
15
)
t
.
left
(
40
)
draw_tree
(
branch_len
-
15
)
t
.
right
(
20
)
t
.
backward
(
branch_len
)
# 绘制树干
def
draw_trunk
(
x
):
t
.
up
()
t
.
goto
(
0
,
-
200
)
t
.
down
()
t
.
color
(
"brown"
)
t
.
begin_fill
()
t
.
forward
(
x
)
t
.
left
(
90
)
t
.
forward
(
50
)
t
.
left
(
90
)
t
.
forward
(
x
)
t
.
left
(
90
)
t
.
end_fill
()
# 绘制圣诞树
def
draw_christmas_tree
():
t
.
color
(
"green"
)
draw_tree
(
100
)
draw_trunk
(
100
)
# 绘制装饰
def
draw_decorations
():
t
.
up
()
t
.
goto
(
0
,
-
60
)
t
.
down
()
t
.
color
(
"red"
)
t
.
begin_fill
()
t
.
circle
(
10
)
t
.
end_fill
()
# 绘制地面
def
draw_ground
():
t
.
up
()
t
.
goto
(
0
,
-
200
)
t
.
down
()
t
.
color
(
"brown"
)
t
.
begin_fill
()
t
.
left
(
90
)
t
.
forward
(
300
)
t
.
right
(
90
)
t
.
forward
(
20
)
t
.
right
(
90
)
t
.
forward
(
300
)
t
.
right
(
90
)
t
.
end_fill
()
# 主函数
def
main
():
draw_christmas_tree
()
draw_decorations
()
draw_ground
()
screen
.
mainloop
()
main
()
sd.py
0 → 100644
View file @
3def2763
# 导入Python标准库中的turtle模块,用于绘制
import
turtle
# 设置绘图窗口的标题
turtle
.
title
(
"Simple Christmas Tree"
)
# 创建一个Turtle对象,用于绘图
tree
=
turtle
.
Turtle
()
# 设置绘图窗口的尺寸
turtle
.
window_width
=
400
turtle
.
window_height
=
400
# 设置树的初始位置和颜色
tree
.
penup
()
tree
.
goto
(
0
,
180
)
tree
.
pendown
()
tree
.
color
(
"brown"
)
# 绘制树的主干
tree
.
begin_fill
()
tree
.
forward
(
100
)
# 绘制树的三个分支
for
i
in
range
(
3
):
tree
.
right
(
120
)
tree
.
forward
(
40
)
tree
.
left
(
60
)
tree
.
forward
(
100
//
(
4
**
i
))
tree
.
right
(
60
)
tree
.
forward
(
40
)
# 完成绘制
tree
.
end_fill
()
# 关闭绘图窗口
turtle
.
done
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment