-
Notifications
You must be signed in to change notification settings - Fork 1
/
Five-StarredRedFlag.py
126 lines (88 loc) · 2.83 KB
/
Five-StarredRedFlag.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from turtle import *
from math import *
from time import *
# Star angle configuration, unit: degree
star_angle = [18,90,162,234,306,18]
# Star angle offset, unit: degree
angle_off = [0, 30.9, 8.1, -8.1,-30.9]
# Draw five star sequence
draw_seq = [0,2,4,1,3,0]
# Set star radius size
def set_rad_size(flag_len):
rad_list = []
rad_list.append(flag_len/10)
rad_list.append(flag_len/30)
rad_list.append(flag_len/30)
rad_list.append(flag_len/30)
rad_list.append(flag_len/30)
return rad_list;
# Set star position x asix offset
def set_x_offset(length):
offset_x_list = []
offset_x_list.append(-1 * length/2 + length / 6)
offset_x_list.append(-1 * length/2 + length * 0.3)
offset_x_list.append(-1 * length/2 + length * 0.4)
offset_x_list.append(-1 * length/2 + length * 0.4)
offset_x_list.append(-1 * length/2 + length * 0.3)
return offset_x_list;
# Set star position y asix offset
def set_y_offset(hight):
offset_y_list = []
offset_y_list.append(hight * 0.25)
offset_y_list.append(hight * 0.4)
offset_y_list.append(hight * 0.3)
offset_y_list.append(hight * 0.15)
offset_y_list.append(hight * 0.05)
return offset_y_list;
# Star draw star
def draw_star(rad_size,offset_x_val,offset_y_val,angle_offset):
penup()
# Set pen color to yellow
color("yellow")
begin_fill()
for i in range(len(star_angle)):
# Calculate the radians of the five angles relative to the center
radian = (star_angle[draw_seq[i]] + angle_offset) / 180 * pi
x = rad_size * cos(radian)
y = rad_size * sin(radian)
# Move to position (x,y)
setpos(x+ offset_x_val,y+ offset_y_val)
pendown()
end_fill()
# Draw red flag
def draw_flag(length,hight):
penup()
setpos(-1 * length/2,-1 * hight/2)
pendown()
color("red")
begin_fill()
fd(length)
left(90)
fd(hight)
left(90)
fd(length)
left(90)
fd(hight)
end_fill()
def main():
FLAG_LENTH = 900
FLAG_HIGHT = FLAG_LENTH * 2 /3
flag_length = FLAG_LENTH
flag_hight = FLAG_HIGHT
for len_index in range(1):
reset()
rad = set_rad_size(flag_length)
offset_x = set_x_offset(flag_length)
offset_y = set_y_offset(flag_hight)
# Start draw red flag
draw_flag(flag_length,flag_hight)
# Start draw five stars
for index in range(5):
draw_star(rad[index],offset_x[index],offset_y[index],angle_off[index])
color("red")
penup()
sleep(1)
flag_length = FLAG_LENTH * (len_index + 1)
flag_hight = FLAG_HIGHT * (len_index + 1)
main()
mainloop()