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_a.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
29 lines (26 loc) · 1.28 KB
master
Breadcrumbs
learnpython
/
Code
/
Turtle
/
Turtle02_a.py
Copy path
Top
File metadata and controls
Code
Blame
29 lines (26 loc) · 1.28 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
'''
功能:绘制彩虹
重点:颜色的表示方法、循环结构程序设计、使用列表和元组表示数据集合
作者:薛景
最后修改于:2019/05/27
'''
import
turtle
t
=
turtle
.
Turtle
()
t
.
shape
(
"turtle"
)
'''
计算机中表示颜色的第二种方法是用三个0~255的整数来表示红、绿、蓝,通过百度我们可
以查到七种彩虹颜色的标准配比,但是在使用这种模式表示颜色之前,必须使用colormode
函数改变小海龟的颜色模式,下面列表中的每一个三元组都是一种颜色,最后一个是天蓝色。
'''
turtle
.
colormode
(
255
)
colors
=
[(
255
,
0
,
0
), (
255
,
165
,
0
), (
255
,
255
,
0
), (
0
,
255
,
0
),\
(
0
,
127
,
255
), (
0
,
0
,
255
), (
139
,
0
,
255
),
"skyblue"
]
turtle
.
bgcolor
(
colors
[
7
])
# 把背景设置成天蓝色,注意列表元素的序号从0开始哟
for
i
in
range
(
10
,
2
,
-
1
):
t
.
color
(
colors
[
10
-
i
])
# 从colors列表中顺序选择其中的颜色
t
.
begin_fill
()
# 与同心圆不同,构成半圆区域的起始点就是原点
t
.
goto
(
20
*
i
,
0
)
t
.
setheading
(
90
)
t
.
circle
(
20
*
i
,
180
)
# 第二个参数表示绘制弧的角度,180度就是半圆
t
.
home
()
# 回到海龟初始的位置,构成封闭的半圆形
t
.
end_fill
()
# 对这个封闭的半圆进行颜色填充
You can’t perform that action at this time.