Skip to content

Commit b33b42e

Browse files
got to 01 Numbers and Strings (2/2/25)
1 parent 3c3ef5b commit b33b42e

18 files changed

Lines changed: 369 additions & 87 deletions

lessons/00_Turtles/13_Flaming_Ninja_Star.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def getRandomColor():
1313
return "#%06X" % (random.randint(0, 0xFFFFFF))
1414

1515

16-
colors = ["red", "blue", "green", "yellow", "orange"]
16+
colors = ["pink", "blue", "red", "yellow", "orange"]
1717

1818

1919
def getNextColor(i):
@@ -22,7 +22,7 @@ def getNextColor(i):
2222
turtle.setup (width=600, height=600)
2323
window = turtle.Screen()
2424

25-
baseSize = 200 # the size of the black part of the star
25+
baseSize = 115 # the size of the black part of the star
2626
flameSize = 130 # the length of the flaming arms
2727

2828
t = turtle.Turtle()
@@ -46,7 +46,7 @@ def getNextColor(i):
4646

4747
t.forward(flameSize)
4848

49-
t.right(170)
49+
t.right(172)
5050

5151
t.forward(flameSize)
5252

lessons/00_Turtles/14_Crazy_Spiral.py

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,110 @@
66
"""
77

88
... # Copy code to make a turtle and set up the window
9+
import random
10+
import turtle
11+
t = turtle.Turtle() # Create a turtle named t
12+
def getRandomColor():
13+
return "#%06X" % (random.randint(0, 0xFFFFFF))
914

10-
t = ... # Create a turtle named t
1115

16+
colors = ["pink", "blue", "red", "yellow", "orange"]
17+
18+
19+
def getNextColor(i):
20+
return colors[i % len(colors)]
21+
22+
23+
t.shape("turtle")
24+
25+
t.width(2)
26+
27+
t.speed(0)
28+
29+
for i in range(25):
30+
t.pencolor(getRandomColor())
31+
32+
t.fillcolor(getRandomColor())
33+
34+
t.begin_fill()
35+
36+
t.forward(40)
37+
38+
t.right(45)
39+
40+
t.forward(20)
41+
42+
t.right(30)
43+
44+
t.forward(20)
45+
46+
t.left(30)
47+
48+
t.forward(20)
49+
t.right(20)
50+
t.forward(20)
51+
t.right(10)
52+
t.forward(10)
53+
t.end_fill()
54+
55+
t.hideturtle()
56+
57+
turtle.done()
1258

1359

1460
# 1) Complete make_a_shape() to make the turtle move in some pattern.
1561
# For instance, you can make it go left 30 degrees, then forward 50 pixels,
1662
# then right 60 degrees, then forward 100 pixels. Make any shape you like.
63+
import random
64+
import turtle
65+
t = turtle.Turtle() # Create a turtle named t
66+
def getRandomColor():
67+
return "#%06X" % (random.randint(0, 0xFFFFFF))
1768

69+
70+
colors = ["pink", "blue", "red", "yellow", "orange"]
71+
72+
73+
def getNextColor(i):
74+
return colors[i % len(colors)]
75+
76+
77+
t.shape("turtle")
78+
79+
t.width(2)
80+
81+
t.speed(0)
1882
def make_a_shape(t):
1983
"""Make a shape with turtle t. Make it go left or right or forward"""
20-
...
84+
for i in range(25):
85+
t.pencolor(getRandomColor())
86+
87+
t.fillcolor(getRandomColor())
88+
89+
t.begin_fill()
90+
91+
t.forward(40)
92+
93+
t.right(45)
94+
95+
t.forward(20)
96+
97+
t.right(30)
98+
99+
t.forward(20)
100+
101+
t.left(30)
102+
103+
t.forward(20)
104+
t.right(20)
105+
t.forward(20)
106+
t.right(10)
107+
t.forward(10)
108+
t.end_fill()
109+
110+
make_a_shape(5)
111+
112+
t.hideturtle()
21113

22114
# 2) Call make_a_shape() in a loop to make the turtle draw a spiral.
23115
# For instance, you can call make_a_shape() 100 times to make a spiral with 100 shapes.

lessons/00_Turtles/15_Pentagon_Crazy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def getNextColor(i):
2424
myTurtle.speed(0)
2525
myTurtle.width(1)
2626

27-
sides = 5
27+
sides = 11
2828
angle = 360 / sides
2929

3030
for i in range(360):

lessons/00_Turtles/16_Turtle_Spiral.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def getRandomColor():
3030
myTurtle.color("green")
3131

3232
# Use a loop to repeat the code below 50 times
33-
for i in range(50):
33+
for i in range(400):
3434

3535
# Set the turtle color to a random color
3636
myTurtle.pencolor(getRandomColor())
3737

3838
# Move the turtle (5*i) pixels. 'i' is the loop variable
39-
myTurtle.forward(9 * i)
39+
myTurtle.forward(5 * i)
4040

4141
# Turn the turtle (360/7) degrees to the right
42-
myTurtle.right(360 / 7 + i*5)
42+
myTurtle.right(360 / 10)
4343

4444
# Change the turtle width to 'i' (the loop variable)
45-
myTurtle.width(i)
45+
myTurtle.width(2)
4646

4747
# Check the pattern against the picture in the recipe. If it matches, you are done!
4848

0 commit comments

Comments
 (0)