This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-turtle-designs.py
396 lines (298 loc) · 7.03 KB
/
basic-turtle-designs.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# -*- coding: utf-8 -*-
import turle
#basic geometrical shapes
# 3.Pentagon
bob = turtle.Turtle()
bob.pensize(10)
bob.color('black', 'red')
bob.begin_fill()
for i in range(5):
bob.forward(100)
bob.left(72)
bob.end_fill()
# 4.Hexagon
bob = turtle.Turtle()
bob.color('red', 'yellow')
for i in range(6):
bob.forward(100)
bob.left(60)
turtle.done()
# 5.Septagon
bob = turtle.Turtle()
bob.pensize(10)
bob.color('black', 'red')
bob.begin_fill()
for i in range(7):
bob.forward(100)
bob.left(51.42)
bob.end_fill()
turtle.done()
# 6.Octagon
bob = turtle.Turtle()
bob.color('black', 'red')
bob.pensize(5)
bob.begin_fill()
for i in range(8):
bob.forward(100)
bob.left(45)
bob.end_fill()
turtle.done()
# 7.Nonagon
bob = turtle.Turtle()
bob.pensize(10)
bob.color('black', 'red')
bob.begin_fill()
for i in range(9):
bob.forward(100)
bob.left(40)
bob.end_fill()
turtle.done()
# 8.Decagon
bob = turtle.Turtle()
bob.pensize(10)
bob.color('black', 'red')
bob.begin_fill()
for i in range(10):
bob.forward(100)
bob.left(36)
bob.end_fill()
turtle.done()
# 9. Circle
#Circle do not need loops it do not has sides so turtle have a different command for it.
bob = turtle.Turtle()
bob.pensize(10)
bob.color('black', 'red')
bob.begin_fill()
bob.circle(100)
bob.end_fill()
turtle.done()
# 10.Star
bob = turtle.Turtle()
bob.color('black', 'red')
bob.pensize(10)
bob.begin_fill()
for i in range(5):
bob.forward(150)
bob.right(144)
bob.end_fill()
turtle.done()
"""## We now know how to make circles. Let's experiment and try to draw the Olympic rings."""
#olympic rings
bob = turtle.Turtle()
bob.pensize(6) #Set the thickness of the pen to 6
firstRowColors = ["blue", "black", "red"] #firstRowColors is a list of colors that are present in the first row of logo
for i in range(3):
bob.penup()
bob.pencolor(firstRowColors[i])
bob.goto(i*110, 0)
bob.pendown()
bob.circle(50)
secondRowColors = ["", "yellow","" , "green"]
for i in range(1, 4, 2):
bob.penup()
bob.pencolor(secondRowColors[i])
bob.goto(i*55, -50)
bob.pendown()
bob.circle(50)
bob.hideturtle()
turtle.done()
"""## Spider web"""
t = turtle.Turtle()
t.speed(0)
#Code for building radical thread
for i in range(6):
t.forward(150)
t.backward(150)
t.right(60)
#Code for building spiral thread
side = 150
for i in range(15):
t.penup()
t.goto(0,0)
t.pendown()
t.setheading(0)
t.forward(side)
t.right(120)
for i in range(6):
t.forward(side)
t.right(60)
side = side - 10
"""## Let us see some tally marks"""
tallymarks = turtle.Turtle()
number = int(input("Enter a number: ")) #Asking user to enter a number
tallymarks.right(90)
x = 0
for i in range(1,number+1):
if(i%5 == 0): #For every fifth number, it will draw diagonal line
tallymarks.right(135)
tallymarks.forward(30*math.sqrt(2))
tallymarks.right(225)
else: #For other numbers, it will draw vertical line
tallymarks.penup()
tallymarks.goto(x*10,0)
tallymarks.pendown()
tallymarks.forward(30)
x = x + 1
"""## Now, What about drawing a spiral square?"""
t = turtle.Turtle()
t.speed(10)
side = 200
for i in range(100):
t.forward(side)
t.right(90) #Exterior angle of a square is 90 degree
side = side - 2
t.hideturtle()
"""## Now, let's start with a cool design!"""
bob = turtle.Turtle()
bob.color("red", "yellow")
bob.speed(10)
bob.begin_fill()
for i in range(50):
bob.forward(300)
bob.left(170)
bob.end_fill()
turtle.done()
import turtle
import math
import random
wn = turtle.Screen()
wn.bgcolor('black')
Albert = turtle.Turtle()
Albert.speed(0)
Albert.color('white')
rotate=int(360)
def drawCircles(t,size):
for i in range(10):
t.circle(size)
size=size-4
def drawSpecial(t,size,repeat):
for i in range (repeat):
drawCircles(t,size)
t.right(360/repeat)
drawSpecial(Albert,100,10)
Steve = turtle.Turtle()
Steve.speed(0)
Steve.color('yellow')
rotate=int(90)
def drawCircles(t,size):
for i in range(4):
t.circle(size)
size=size-10
def drawSpecial(t,size,repeat):
for i in range (repeat):
drawCircles(t,size)
t.right(360/repeat)
drawSpecial(Steve,100,10)
Barry = turtle.Turtle()
Barry.speed(0)
Barry.color('blue')
rotate=int(80)
def drawCircles(t,size):
for i in range(4):
t.circle(size)
size=size-5
def drawSpecial(t,size,repeat):
for i in range (repeat):
drawCircles(t,size)
t.right(360/repeat)
drawSpecial(Barry,100,10)
Terry = turtle.Turtle()
Terry.speed(0)
Terry.color('orange')
rotate=int(90)
def drawCircles(t,size):
for i in range(4):
t.circle(size)
size=size-19
def drawSpecial(t,size,repeat):
for i in range (repeat):
drawCircles(t,size)
t.right(360/repeat)
drawSpecial(Terry,100,10)
Will = turtle.Turtle()
Will.speed(0)
Will.color('pink')
rotate=int(90)
def drawCircles(t,size):
for i in range(4):
t.circle(size)
size=size-20
def drawSpecial(t,size,repeat):
for i in range (repeat):
drawCircles(t,size)
t.right(360/repeat)
drawSpecial(Will,100,10)
"""#### You could just experiment and play around with this thing and make cool designs"""
# Like see how I'm doing it!
bob = turtle.Turtle()
bob.color("red", "yellow")
bob.speed(10)
bob.begin_fill()
for i in range(50):
bob.forward(math.sqrt(i))
bob.left(170)
bob.end_fill()
turtle.done()
"""#### Did you observed You could just experiment and explore what happens"""
bob = turtle.Turtle()
bob.color("red", "yellow")
bob.speed(10)
bob.begin_fill()
for i in range(50):
bob.forward(math.sqrt(i)*10)
bob.left(170)
bob.end_fill()
turtle.done()
"""#### You see it It is just fun!! Just experiment and explore around with the maths library and the numbers and EXPLORE! What if I do something more"""
bob = turtle.Turtle()
bob.color("red", "yellow")
bob.speed(10)
bob.begin_fill()
for i in range(50):
bob.forward(math.sqrt(i)*10)
bob.left(i%90)
bob.end_fill()
turtle.done()
"""Let's continue"""
bob = turtle.Turtle()
bob.color("red")
bob.speed(10)
for i in range(100):
bob.forward(20)
bob.left(math.sin(i/10)*15)
bob.left(20)
turtle.done()
bob = turtle.Turtle()
bob.color("red")
bob.speed(10)
for i in range(2000):
bob.forward(10)
bob.left(math.sin(i/10)*25)
bob.left(20)
turtle.done()
"""See both the designs by changing some numbers, you can observee output seems to change!!
You could also do the same by using the random library!
"""
AISC = turtle.Turtle()
AISC.getscreen().bgcolor("#994444")
#for i in range(5):
# AISC.forward(10)
# AISC.left(216)
AISC.penup()
AISC.goto((-200, 50))
AISC.pendown()
AISC.speed(10)
AISC.pensize(3)
def star(turtle, size):
if size <= 10:
return
else:
turtle.begin_fill()
for i in range(5):
turtle.forward(size)
star(turtle, size/3)
turtle.left(216)
turtle.end_fill
star(AISC, 300)
AISC.hideturtle()
turtle.done()