Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
xuejing80
learnpython
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
learnpython
/
Code
/
Turtle
/
Turtle02.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
34 lines (31 loc) · 1.53 KB
master
Breadcrumbs
learnpython
/
Code
/
Turtle
/
Turtle02.py
Copy path
Top
File metadata and controls
Code
Blame
34 lines (31 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
功能:绘制同心圆
重点:随机数的概念、颜色的表示方法、range函数的用法、循环结构程序设计
作者:薛景
最后修改于:2019/05/27
'''
import
turtle
from
random
import
random
# 从random函数库中导入random函数,该函数可以一个生成[0,1)区间上的随机数
t
=
turtle
.
Turtle
()
t
.
shape
(
"turtle"
)
'''
为了防止后画的圆遮挡先画的圆,所以同心圆必须从大往小画,因此循环变量i的值,必须从
大往小递减。观察本程序中的range函数,可以发现第一个参数表示起始值,第二个参数表示
终止值(不被包含在产生的序列中),第三个表示递增量(如果是负数,生成的序列就是递减
的关系),大家可以调整程序中的range函数的参数为以下组合,试试看效果:
(10,5,-1) # 只绘制5个圆就结束了
(10,0,-2) # 同样绘制5个圆,递减速度加大
(5,0,-1) # 还是绘制5个圆,起始圆变小了
'''
for
i
in
range
(
10
,
0
,
-
1
):
t
.
goto
(
20
*
i
,
0
)
# 移动海龟到圆上,goto函数的参数是平面坐标系的坐标(x,y)
t
.
setheading
(
90
)
# 调整方向,准备画圆
t
.
color
(
random
(),
random
(),
random
())
# 上面的语句用来设置圆的颜色,三个0~1之间的数分别表示红色、绿色、蓝色的比重
t
.
begin_fill
()
t
.
circle
(
20
*
i
)
# circle函数的参数为半径,其正负决定了往左还是往右画圆
t
.
end_fill
()
'''
思考题:上面的程序,如何修改,就可以画出美丽的彩虹呢?
'''
You can’t perform that action at this time.