Skip to content

Commit 48b2b1f

Browse files
Add files via upload
1 parent c069dc6 commit 48b2b1f

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

turtle_challenge.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
from turtle import Turtle, Screen
2+
import random
3+
4+
milo = Turtle()
5+
milo.shape("turtle")
6+
milo.color("red")
7+
milo.forward(100)
8+
milo.right(90)
9+
10+
# Drawing a square with turtle challenge 1 option 1
11+
milo.forward(100)
12+
milo.right(90)
13+
milo.forward(100)
14+
milo.right(90)
15+
milo.forward(100)
16+
milo.right(90)
17+
milo.forward(100)
18+
milo.right(90)
19+
20+
# Drawing a square with turtle challenge 1 option 2
21+
for _ in range(4):
22+
milo.forward(100)
23+
milo.right(90)
24+
25+
# Drawing a dashed line with turtle challenge 2
26+
for _ in range(15):
27+
milo.forward(10)
28+
milo.penup()
29+
milo.forward(10)
30+
milo.pendown()
31+
32+
# Drawing a different shapes with turtle challenge 3
33+
colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"]
34+
35+
def draw_shape(num_sides):
36+
angle = 360 / num_sides
37+
for _ in range(num_sides):
38+
milo.forward(100)
39+
milo.right(angle)
40+
41+
for shape_side_n in range(3, 11):
42+
milo.color(random.choice(colours))
43+
draw_shape(shape_side_n)
44+
45+
# Drawing a Random Walk with list of colours turtle challenge 4
46+
colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"]
47+
directions = [0, 90, 180, 270]
48+
milo.pensize(10)
49+
milo.speed(("fastest"))
50+
51+
for _ in range(200):
52+
milo.color(random.choice(colours))
53+
milo.forward(30)
54+
milo.setheading(random.choice(directions))
55+
56+
# Drawing a Random Walk with random colours turtle challenge 5
57+
import turtle as t
58+
import random
59+
60+
milo = t.Turtle()
61+
t.colormode(255)
62+
63+
def random_color():
64+
r = random.randint(0, 255)
65+
g = random.randint(0, 255)
66+
b = random.randint(0, 255)
67+
random_color = (r, g, b)
68+
return random_color
69+
70+
directions = [0, 90, 180, 270]
71+
milo.pensize(10)
72+
milo.speed(("fastest"))
73+
74+
for _ in range(200):
75+
milo.color(random_color())
76+
milo.forward(30)
77+
milo.setheading(random.choice(directions))
78+
79+
# Making a Spirograph with turtle challenge 6
80+
import turtle as t
81+
import random
82+
83+
milo = t.Turtle()
84+
t.colormode(255)
85+
86+
def random_color():
87+
r = random.randint(0, 255)
88+
g = random.randint(0, 255)
89+
b = random.randint(0, 255)
90+
color = (r, g, b)
91+
return color
92+
93+
milo.speed(("fastest"))
94+
95+
def draw_spirograph(size_of_gap):
96+
for _ in range(int(360 / size_of_gap)):
97+
milo.color(random_color())
98+
milo.circle(100)
99+
milo.setheading(milo.heading() + size_of_gap)
100+
101+
draw_spirograph(5)
102+
103+
screen = t.Screen()
104+
screen.exitonclick()
105+

0 commit comments

Comments
 (0)