Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson10-3
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
eeb5969a
authored
Oct 02, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
5bd73894
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
ddd.py
ddd.py
View file @
eeb5969a
import
turtle
import
turtle
radius
=
80
import
random
turtle
.
color
(
"red"
,
"pink"
)
# 设置画笔颜色和填充色
width
=
800
# 窗体宽度
turtle
.
pensize
(
2
)
# 设置画笔大小
height
=
600
# 窗体高度
turtle
.
begin_fill
()
# 开始填充
num
=
100
# 雪花数
turtle
.
left
(
45
)
# 左转45度
turtle
.
setup
(
width
,
height
)
# 窗口大小宽度800像素,高度600像素
turtle
.
fd
(
2
*
radius
)
# 前进
turtle
.
tracer
(
False
)
# 关闭动画,显示结果更快
turtle
.
circle
(
radius
,
180
)
# 画半圆
turtle
.
bgcolor
(
"black"
)
# 设置背景颜色为黑色
turtle
.
right
(
90
)
# 右转90度
turtle
.
circle
(
radius
,
180
)
# 画半圆
turtle
.
fd
(
2
*
radius
)
# 前进200像素
turtle
.
end_fill
()
# 结束填充
turtle
.
hideturtle
()
# 隐藏指针
turtle
.
hideturtle
()
# 隐藏指针
turtle
.
done
()
# 结束,停留在当前界面
turtle
.
pensize
(
2
)
# 设置画笔大小
\ No newline at end of file
for
i
in
range
(
num
):
# 循环绘制每一个雪花
r
,
g
,
b
=
random
.
random
(),
random
.
random
(),
random
.
random
()
# 随机生成颜色
turtle
.
pencolor
(
r
,
g
,
b
)
# 设置画笔颜色
turtle
.
penup
()
# 提起画笔,需要移动位置
turtle
.
setx
(
random
.
randint
(
-
width
//
2
,
width
//
2
))
# 设置 x 坐标位置
turtle
.
sety
(
random
.
randint
(
-
height
//
2
,
height
//
2
))
# 设置 y 坐标位置
turtle
.
pendown
()
# 按下画笔,准备绘画
lines
=
random
.
randint
(
6
,
12
)
# 随机生成雪花的线条数
snow_size
=
random
.
randint
(
8
,
16
)
# 随机生成线条的长度
for
j
in
range
(
lines
):
# 循环画线条
turtle
.
forward
(
snow_size
)
# 画线条
turtle
.
backward
(
snow_size
)
# 回到原位置
turtle
.
right
(
360
/
lines
)
# 改变角度,线条均匀分开
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