Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson15-diy1
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
617082b3
authored
May 23, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
938c4ef3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
my_tree.py
my_tree.py
View file @
617082b3
import
turtle
import
random
#导入random
模块
################
import
random
#导入随机
模块
pen
=
turtle
.
Turtle
()
pen
.
speed
(
0
)
#设置画笔速度
pen
.
hideturtle
()
#隐藏画笔
pen
.
speed
(
0
)
#设置画笔速度
pen
.
color
(
'sienna'
)
# 画布大小
w
=
turtle
.
Screen
()
w
.
bgcolor
(
'wheat'
)
# wheat小麦
# 移动到起点
pen
.
up
()
pen
.
goto
(
0
,
-
220
)
pen
.
down
()
pen
.
left
(
90
)
pen
.
up
()
pen
.
backward
(
150
)
# 后退
pen
.
down
()
#####################
def
tree
(
n
):
#创建函数
if
n
>=
0
:
if
n
<=
12
:
#画樱花
color
_list
=
[
'snow'
,
'lightcoral'
]
color
=
random
.
choice
(
color_list
)
#在列表中随机抽取一个设置
颜色
pen
.
color
(
color
)
pen
.
pensize
(
n
/
3
)
else
:
#画树干
pen
.
color
(
'sienna'
)
#设置画笔颜色
def
tree
(
n
):
#画树枝
if
n
>=
0
:
#画樱花树的条件
if
n
<=
12
:
#画樱花和画树枝的条件
color_list
=
[
'snow'
,
"lightcoral"
]
color
=
random
.
choice
(
color_list
)
#利用random模块在color_list里面随机抽取一个颜色
pen
.
color
(
color
)
#设置颜色为抽取到的
颜色
pen
.
pensize
(
n
/
3
)
else
:
#否则n>12画树枝
pen
.
color
(
'sienna'
)
pen
.
pensize
(
n
/
10
)
pen
.
forward
(
n
)
angle
=
random
.
random
()
pen
.
right
(
30
*
angle
)
length
=
1.5
*
random
.
random
()
tree
(
n
-
10
*
length
)
pen
.
left
(
60
*
angle
)
tree
(
n
-
10
*
length
)
pen
.
right
(
30
*
angle
)
pen
.
forward
(
n
+
10
)
#画树干
angle
=
random
.
random
()
#在0和1之间随机抽取一个数字
pen
.
right
(
30
)
length
=
1.5
*
random
.
random
()
#长度
tree
(
n
-
10
)
#画其他小树枝
pen
.
left
(
60
)
tree
(
n
-
10
)
pen
.
right
(
30
)
pen
.
up
()
pen
.
backward
(
n
)
pen
.
backward
(
n
+
10
)
pen
.
down
()
tree
(
60
)
pen
.
up
()
pen
.
goto
(
-
50
,
-
250
)
pen
.
write
(
"韩憨憨"
,
font
=
(
"Arial"
,
50
,
"bold"
))
turtle
.
done
()
tree
(
100
)
turtle
.
done
()
\ No newline at end of file
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