-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
208 lines (171 loc) · 5.23 KB
/
main.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# tiling program
# Developers: Kravtsov - 80%
# Mikhailov - 30%
# Mauter - 10%
import turtle as t
import math as m
# main function, which contains a dictionary of colors, as well as calls to other functions
def main():
colors = {2: 'red', -1: 'orange', 1: 'yellow', -3: 'green', 3: 'blue', -2: 'purple', 4: 'black', -4: 'white'}
print('''
Доступные цвета раскрашивания:
1. red
2. orange
3. yellow
4. green
5. blue
6. purple
7. black
8. white''')
color_i = get_color_choice()
n = int(input('Введите количество шестиугольников в ряду(от 4 до 20):'))
if not 4 <= n <= 20:
n = try_n(n)
for i in colors:
if color_i == colors[i]:
color = i
if n == 4:
t.up()
t.speed(0)
hexagons_tiles(n, n, -490, 250, 125, color, 1.615, 1.85)
t.mainloop()
elif n == 5:
t.up()
t.speed(0)
hexagons_tiles(n, n, -400, 250, 100, color, 1.64, 1.825)
t.mainloop()
elif n == 6:
t.up()
t.speed(0)
hexagons_tiles(n, n, -450, 250, 80, color, 1.655, 1.81)
t.mainloop()
elif n == 7:
t.up()
t.speed(0)
hexagons_tiles(n, n, -400, 280, 70, color, 1.67, 1.79)
t.mainloop()
elif n == 8:
t.up()
t.speed(0)
hexagons_tiles(n, n, -450, 280, 60, color, 1.68, 1.78)
t.mainloop()
elif n == 9:
t.up()
t.speed(0)
hexagons_tiles(n, n, -380, 295, 55, color, 1.69, 1.775)
t.mainloop()
elif n == 10:
t.up()
t.speed(0)
hexagons_tiles(n, n, -450, 290, 48, color, 1.69, 1.775)
t.mainloop()
elif n == 11:
t.up()
t.speed(0)
hexagons_tiles(n, n, -385, 300, 42, color, 1.695, 1.77)
t.mainloop()
elif n == 12:
t.up()
t.speed(0)
hexagons_tiles(n, n, -415, 300, 38, color, 1.7, 1.765)
t.mainloop()
elif n == 13:
t.up()
t.speed(0)
hexagons_tiles(n, n, -385, 300, 35, color, 1.7, 1.765)
t.mainloop()
elif n == 14:
t.up()
t.speed(0)
hexagons_tiles(n, n, -405, 300, 32, color, 1.705, 1.76)
t.mainloop()
elif n == 15:
t.up()
t.speed(0)
hexagons_tiles(n, n, -380, 300, 30, color, 1.705, 1.76)
t.mainloop()
elif n == 16:
t.up()
t.speed(0)
hexagons_tiles(n, n, -410, 310, 29, color, 1.71, 1.755)
t.mainloop()
elif n == 17:
t.up()
t.speed(0)
hexagons_tiles(n, n, -390, 315, 27, color, 1.71, 1.755)
t.mainloop()
elif n == 18:
t.up()
t.speed(0)
hexagons_tiles(n, n, -405, 315, 25, color, 1.71, 1.755)
t.mainloop()
elif n == 19:
t.up()
t.speed(0)
hexagons_tiles(n, n, -390, 315, 24, color, 1.715, 1.75)
t.mainloop()
elif n == 20:
t.up()
t.speed(0)
hexagons_tiles(n, n, -405, 315, 22.5, color, 1.715, 1.75)
t.mainloop()
# function checks input validation color
def get_color_choice():
color_i = input('Введите цвет:')
lst = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'black', 'white']
while color_i not in lst:
color_i = input('Некорректный ввод цвета. Повторите еще раз:')
return color_i
# the function checks the check of input angles
def try_n(n):
lst = []
for i in range(4, 20):
lst.append(str(i))
while n not in lst:
n = input('Некорректный ввод шестиугольников. Повторите еще раз:')
return int(n)
# function draws and paints a hexagon
def draw_hexagon(x, y, side_len, color):
colors = {2: 'red', -1: 'orange', 1: 'yellow', -3: 'green', 3: 'blue', -2: 'purple', 4: 'black', -4: 'white'}
t.pencolor('black')
t.begin_fill()
t.up()
t.goto(x, y)
t.right(30)
t.down()
for i in range(6):
t.forward(side_len)
t.left(60)
t.left(30)
t.fillcolor(colors[color])
t.end_fill()
t.up()
# the recursive function of drawing hexagons in a row
def hexagons_line(n, x, y, side_len, color):
if n == 1:
draw_hexagon(x, y, side_len, color)
else:
t.up()
draw_hexagon(x, y, side_len, color)
t.up()
hexagons_line(n - 1, x + (m.sqrt(3) * side_len), y, side_len, -color)
# a recursive function that generates masonry and displays
def hexagons_tiles(n1, n, x, y, side_len, color, coef2, coef1):
if n1 == 1:
hexagons_line(n, x, y, side_len, color)
else:
hexagons_line(n, x, y, side_len, color)
if n1 % 2 != 0:
t.up()
t.backward(((n - 1) * (coef1 * side_len)) + (side_len / 2))
x_new = t.xcor()
y_new = y - side_len - (side_len / 2)
t.up()
hexagons_tiles(n1 - 1, n, x_new, y_new, side_len, color, coef2, coef1)
else:
t.up()
t.backward(((n - 1) * (coef2 * side_len)) - (side_len / 2))
x_new = t.xcor()
y_new = y - side_len - (side_len / 2)
hexagons_tiles(n1 - 1, n, x_new, y_new, side_len, color, coef2, coef1)
main()