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
/
Turtle01_a.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
35 lines (31 loc) · 1.26 KB
master
Breadcrumbs
learnpython
/
Code
/
Turtle
/
Turtle01_a.py
Copy path
Top
File metadata and controls
Code
Blame
35 lines (31 loc) · 1.26 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
35
'''
功能:将五角星放置在绘图区域的中央
重点:
作者:薛景
最后修改于:2019/05/26
'''
import
turtle
import
math
# 接下来的程序中需要使用三角函数,补充导入math函数库
t
=
turtle
.
Turtle
()
t
.
shape
(
"turtle"
)
t
.
color
(
"red"
)
# 海龟会从某一个尖角上开始绘制五角星,所以先将海龟移动到尖角上,并调整好方向
t
.
setheading
(
90
)
# 设置海龟的运动方向为正上方
'''
接下来这条语句有几个知识点需要说明一下:
1. 海龟向上移动的距离应该是五角星的外接圆半径
2. 把该外接圆半径和五角星的短边作为三角形的两条边,就可用正弦定理求得该外接圆半径
3. math函数库中,三角函数参数的单位是弧度,故需要使用radians函数将角度转换成弧度
'''
r
=
100
*
math
.
sin
(
math
.
radians
(
126
))
/
math
.
sin
(
math
.
radians
(
36
))
t
.
forward
(
r
)
t
.
left
(
180
-
18
)
# 18度是五角星尖角度数36的一半,请仔细观察绘制过程
# 调整好方向之后,就可以按照老办法绘制五角星了
t
.
begin_fill
()
for
i
in
range
(
5
):
t
.
forward
(
100
)
t
.
right
(
72
)
t
.
forward
(
100
)
t
.
left
(
144
)
t
.
end_fill
()
t
.
hideturtle
()
# 为了不影响最后的效果,还可以把小海龟隐藏起来
You can’t perform that action at this time.