-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTurtle04.py
More file actions
52 lines (47 loc) · 1.46 KB
/
Turtle04.py
File metadata and controls
52 lines (47 loc) · 1.46 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'''
功能:绘制五星红旗
重点:三角函数的使用、角度和弧度的换算
作者:薛景
最后修改于:2019/05/30
'''
import turtle, math
t = turtle.Turtle()
t.shape("turtle")
def drawStar(x, y, r, color, heading):
t.up()
t.goto(x, y)
t.down()
t.color(color)
t.setheading(heading)
edge=r*math.sin(math.radians(36))/math.sin(math.radians(126))
t.forward(r)
t.left(180-18)
t.begin_fill()
for i in range(5):
t.forward(edge)
t.right(72)
t.forward(edge)
t.left(144)
t.end_fill()
# 画五星红旗的背景,把整个国旗看作600*400大小,左上角的坐标就是(-300,200)
t.color("red")
t.goto(-300,200)
t.begin_fill()
t.forward(600)
t.right(90)
t.forward(400)
t.right(90)
t.forward(600)
t.right(90)
t.forward(400)
t.end_fill()
# 画大星星
drawStar(-200, 100, 60, "yellow", 90)
# 画小星星,最难的就是求每个小星星的朝向,利用小星星和大星星中心点构成的直角三角形可求
# math函数库中反正切函数结果的单位是弧度,务必先用degrees先换算成角度
# 又因为反正切函数的值域在(-90,90)上,所有记得要加180度哟
drawStar(-100, 160, 20, "yellow", math.degrees(math.atan(-60/-100))+180)
drawStar(-60, 120, 20, "yellow", math.degrees(math.atan(-20/-140))+180)
drawStar(-60, 60, 20, "yellow", math.degrees(math.atan(40/-140))+180)
drawStar(-100, 20, 20, "yellow", math.degrees(math.atan(80/-100))+180)
t.hideturtle()