-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
332 lines (308 loc) · 8.48 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import turtle
def set_turtle_attributes(turtle_obj, color, speed, width):
#Set attributes for a turtle object.
turtle_obj.color(color)
turtle_obj.speed(speed)
turtle_obj.width(width)
def blank(val):
#Fill the background with a single color.
s = turtle.Turtle()
screen = turtle.Screen()
screen.bgcolor(val)
set_turtle_attributes(s, val, 10, 12000)
s.forward(1)
def multi_star(colors, layers):
#Draw a multicolor star pattern.
t = turtle.Turtle()
screen = turtle.Screen()
set_turtle_attributes(t, colors[0], layers, 3)
for i in range(layers * 8):
t.color(colors[i % len(colors)])
t.forward(i * 4)
t.left(150)
def multi_sqr(colors, num_squares):
#Draw a series of multicolor squares.
u = turtle.Turtle()
screen = turtle.Screen()
set_turtle_attributes(u, colors[0], num_squares, 3)
for _ in range(num_squares):
for color in colors:
u.color(color)
u.left(12)
for _ in range(4):
u.forward(210)
u.left(95)
def multi_hexa(colors, num_hexagons):
#Draw multicolor hexagons.
t = turtle.Turtle()
screen = turtle.Screen()
set_turtle_attributes(t, colors[0], num_hexagons, 1)
for x in range(num_hexagons * 6):
t.color(colors[x % len(colors)])
t.width(x // 100 + 1)
t.forward(x)
t.left(59)
def sun(color):
#Draw a sun-like spiral pattern.
t = turtle.Turtle()
screen = turtle.Screen()
set_turtle_attributes(t, color, 150, 2)
t.goto(0, 180)
a, b = 0, 0
while b < 205:
t.forward(a)
t.right(b)
a += 3
b += 1
def schlogo(main_color, accent_color):
#Draw the Sindhi High School logo.
s = turtle.Turtle()
screen = turtle.Screen()
set_turtle_attributes(s, main_color, 150, 2)
for i in range(5):
s.color(main_color)
s.right(100)
s.forward(122)
s.right(80)
s.forward(122)
s.right(80)
s.forward(122)
s.right(100)
s.forward(170)
s.backward(90)
s.left(90)
for i in range(34):
s.left(3)
s.forward(1)
s.forward(80)
s.left(168)
s.forward(102)
s.left(90)
for i in range(35):
s.right(3)
s.forward(1)
s.forward(70)
s.right(85)
s.forward(123)
s.right(80)
s.forward(71)
s.right(90)
s.forward(2)
s.color(accent_color)
s.forward(118)
s.right(90)
s.forward(85)
s.backward(177)
s.left(90)
s.forward(1)
s.right(90)
s.forward(92)
s.right(90)
s.forward(120)
s.color(main_color)
s.forward(2)
s.left(180)
s.forward(1)
s.right(90)
s.forward(41)
s.left(80)
s.forward(2)
s.right(360)
s.forward(1)
s.color(accent_color)
s.forward(120)
s.left(100)
s.forward(20)
s.left(90)
s.forward(119)
s.color(main_color)
s.forward(2)
s.color(accent_color)
s.forward(10)
s.right(90)
s.color(main_color)
s.forward(100)
s.left(90)
s.left(63)
for i in range(52):
s.left(1)
s.forward(2)
s.right(0)
s.forward(1)
s.left(155)
s.forward(47)
s.right(90)
s.forward(18)
s.right(42)
for i in range(27):
s.left(3)
s.forward(3)
s.left(98)
for i in range(28):
s.left(3)
s.forward(3)
s.left(49)
s.color(main_color)
s.color(accent_color)
s.forward(40)
s.left(80)
s.forward(106)
s.left(100)
s.color(main_color)
s.forward(120)
s.backward(40)
s.color(accent_color)
s.backward(30)
s.forward(11)
s.left(90)
s.forward(16)
s.color(main_color)
s.left(90)
s.forward(56)
s.backward(112)
s.forward(40)
s.color(accent_color)
s.forward(26)
s.right(90)
s.forward(16)
s.left(90)
s.forward(8)
s.color(main_color)
s.forward(36)
s.color(accent_color)
s.right(101)
s.forward(16)
s.right(79)
s.color(main_color)
s.forward(31)
s.backward(31)
s.left(79)
s.color(accent_color)
s.forward(16)
s.right(79)
s.color(main_color)
s.forward(23)
s.backward(23)
s.left(79)
s.color(accent_color)
s.forward(16)
s.right(79)
s.color(main_color)
s.forward(24)
s.backward(24)
s.left(79)
s.color(accent_color)
s.forward(16)
s.right(79)
s.color(main_color)
s.forward(24)
s.backward(24)
s.color(accent_color)
s.left(79)
s.forward(11)
s.right(79)
s.forward(37)
s.color(main_color)
s.forward(2)
s.color(accent_color)
s.forward(47)
s.right(79)
s.forward(16)
s.color(main_color)
s.right(101)
s.forward(37)
s.backward(37)
s.left(101)
s.color(accent_color)
s.forward(16)
s.right(101)
s.color(main_color)
s.forward(30)
s.backward(30)
s.left(101)
s.color(accent_color)
s.forward(16)
s.right(101)
s.color(main_color)
s.forward(27)
s.backward(27)
s.left(101)
s.color(accent_color)
s.forward(16)
s.right(101)
s.color(main_color)
s.forward(24)
s.backward(24)
s.left(101)
s.color(accent_color)
s.forward(14)
s.right(101)
s.color(main_color)
s.forward(37)
def get_colors():
"""Prompt the user to input a list of colors."""
colors = []
while True:
try:
num_colors = int(input("How many colors do you want? (1-20): "))
if 1 <= num_colors <= 20:
break
else:
print("The number of colors must be between 1 and 20.")
except ValueError:
print("Invalid input. Please enter a number between 1 and 20.")
for _ in range(num_colors):
colors.append(input("Enter color: ").strip().lower())
return colors
def main():
"""Main function to interact with the user and call appropriate drawing functions."""
print(
"------------------------------------------------------------------------------"
)
print("A program to display some color patterns using the turtle module!")
print(
"------------------------------------------------------------------------------"
)
while True:
print("1. Display multicolor stars")
print("2. Display a combination of multicolor squares")
print("3. Display multicolor hexagons")
print("4. Display a sun pattern")
print("5. Display the Sindhi High School logo")
print("6. Exit")
choice = input("Enter your choice: ").strip().lower()
if choice in ("1", "one"):
colors = get_colors()
background_color = input("Enter the background color: ").strip().lower()
layers = int(input("Enter the number of stars per color (0-25): "))
blank(background_color)
multi_star(colors, layers)
elif choice in ("2", "two"):
colors = get_colors()
background_color = input("Enter the background color: ").strip().lower()
num_squares = int(input("Enter the number of squares per color (0-25): "))
blank(background_color)
multi_sqr(colors, num_squares)
elif choice in ("3", "three"):
colors = get_colors()
background_color = input("Enter the background color: ").strip().lower()
num_hexagons = int(input("Enter the number of hexagons per color (0-25): "))
blank(background_color)
multi_hexa(colors, num_hexagons)
elif choice in ("4", "four"):
color = input("Enter the color: ").strip().lower()
background_color = input("Enter the background color: ").strip().lower()
blank(background_color)
sun(color)
elif choice in ("5", "five"):
main_color = input("Enter the main color: ").strip().lower()
accent_color = "black"
background_color = input("Enter the background color: ").strip().lower()
blank(background_color)
schlogo(main_color, accent_color)
elif choice in ("6", "six", "exit", "quit"):
break
else:
print("Invalid choice, please try again!")
if __name__ == "__main__":
main()