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
e0ba0595
authored
May 09, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
a4b5b421
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
my_tree2.py
my_tree2.py
View file @
e0ba0595
...
...
@@ -2,20 +2,30 @@ import turtle
import
random
pen
=
turtle
.
Turtle
()
pen
.
color
(
'sienna'
)
pen
.
color
(
'sienna'
)
#赭色
# 画布大小
w
=
turtle
.
Screen
()
w
.
bgcolor
(
'wheat'
)
# wheat小麦
pen
.
speed
(
0
)
#写字
pen
.
penup
()
pen
.
goto
(
-
400
,
100
)
pen
.
write
(
'宝
\n
剑
\n
锋
\n
从
\n
磨
\n
砺
\n
出'
,
font
=
(
'宋体'
,
20
,
'normal'
))
pen
.
goto
(
0
,
0
)
# 移动到起点
pen
.
left
(
90
)
pen
.
up
()
pen
.
backward
(
150
)
# 后退
pen
.
down
()
pen
.
speed
(
0
)
def
tree
(
n
):
# 画树枝
if
n
>=
0
:
if
n
<=
12
:
#画一个二叉树(二,分型树)
def
tree
(
n
):
if
n
>=
0
:
if
n
<=
12
:
color_list
=
[
'snow'
,
'lightcoral'
]
color
=
random
.
choice
(
color_list
)
pen
.
color
(
color
)
...
...
@@ -23,18 +33,16 @@ def tree(n): # 画树枝
else
:
pen
.
color
(
'sienna'
)
pen
.
pensize
(
n
/
10
)
pen
.
pensize
(
n
/
10
)
pen
.
forward
(
n
)
angle
=
random
.
randint
(
0
,
30
)
length
=
random
.
randint
(
1
,
15
)
pen
.
forward
(
n
)
#前进
angle
=
random
.
randint
(
0
,
30
)
#随机生成角度
len
=
random
.
randint
(
1
,
15
)
#随机生成树枝的长度
pen
.
right
(
angle
)
tree
(
n
-
len
gth
)
tree
(
n
-
len
)
pen
.
left
(
2
*
angle
)
tree
(
n
-
len
gth
)
tree
(
n
-
len
)
pen
.
right
(
angle
)
pen
.
up
()
pen
.
penup
()
#抬笔
pen
.
backward
(
n
)
pen
.
down
()
tree
(
60
)
pen
.
pendown
()
#落笔
tree
(
80
)
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