Skip to content

Commit

Permalink
Merge pull request #6 from callysto/turtles-solution-changes
Browse files Browse the repository at this point in the history
changed to use colabturtleplus
  • Loading branch information
mrbubbleman committed Oct 23, 2023
2 parents 3dfbb2d + b6ec9cc commit 3b860c0
Showing 1 changed file with 91 additions and 48 deletions.
139 changes: 91 additions & 48 deletions CallystoAndComputationalThinking/Turtles-Solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"\n",
"We can have fun and create art by commanding turtles to move around the screen.\n",
"\n",
"This uses a Python library called **mobilechelonian**, which is based on code written by students at [MacEwan University](https://www.macewan.ca/) in Edmonton."
"This uses a Python library called [ColabTurtlePlus](https://pypi.org/project/ColabTurtlePlus/), which is an extension of the original **ColabTurtle** by Tolga Atam. "
]
},
{
Expand All @@ -25,7 +25,7 @@
"## Turtle Commands\n",
"\n",
"`t.speed(integer)`\n",
"* Speed of your turtle, 1-10 (hint set your speed to 10) \n",
"* Speed of your turtle, 1-13 (hint set your speed to 13) \n",
"\n",
"`t.pendown()` or `t.penup()`\n",
"* For drawing lines or not \n",
Expand Down Expand Up @@ -65,10 +65,17 @@
},
"outputs": [],
"source": [
"from mobilechelonian import Turtle #import the Turtle module from the mobilechelonian library\n",
"import math #this library will come in handy when making the roof, hint math.sqrt()\n",
"t = Turtle()\n",
"t.speed(10)\n",
"# import the drawing library, ColabTurtlePlus as cTurtle\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"# this library will come in handy when making the roof, hint math.sqrt()\n",
"import math \n",
"\n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"### enter your code below, use the turtle commands above such as t.forward(100) and t.right(90)\n",
"t.forward(100) #hint\n",
"t.right(90)\n",
Expand All @@ -79,9 +86,11 @@
"t.forward(100) #hint\n",
"t.right(90)\n",
"t.right(-45)\n",
"t.forward(100/math.sqrt(2)) #remember your 45-45-90 triangle formula!\n",
"# remember your 45-45-90 triangle formula!\n",
"t.forward(100/math.sqrt(2)) \n",
"t.right(90)\n",
"t.forward(100/math.sqrt(2)) #remember your 45-45-90 triangle formula!"
"# remember your 45-45-90 triangle formula!\n",
"t.forward(100/math.sqrt(2)) "
]
},
{
Expand Down Expand Up @@ -113,13 +122,19 @@
},
"outputs": [],
"source": [
"from mobilechelonian import Turtle\n",
"t = Turtle()\n",
"t.speed(10)\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"for i in range(4): #enter a value for range, how many times do we need to repeat to draw a box?\n",
" t.forward(100) #enter a unit value\n",
" t.right(90) #enter a degree value"
"# enter a value for range, how many times do we need to repeat to draw a box?\n",
"for i in range(4): \n",
" # enter a unit value\n",
" t.forward(100) \n",
" # enter a degree value\n",
" t.right(90) "
]
},
{
Expand All @@ -137,16 +152,23 @@
},
"outputs": [],
"source": [
"from mobilechelonian import Turtle\n",
"t = Turtle()\n",
"t.speed(10)\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"def box(units): #def means define function, in this case our function is called box\n",
" for i in range(4): #enter a value for range. hint: how many times do we need to repeat to draw a box? \n",
"# def means define function, in this case our function is called box\n",
"def box(units): \n",
" # enter a value for range. hint: how many times do we need to repeat to draw a box? \n",
" for i in range(4): \n",
" t.forward(units)\n",
" t.right(90) #enter a degree value\n",
" \n",
"box(100) #enter a unit value for our box function. hint: how many units did we use above?"
" # enter a degree value\n",
" t.right(90)\n",
"\n",
"# enter a unit value for our box function. hint: how many units did we use above?\n",
"box(100)"
]
},
{
Expand All @@ -164,17 +186,24 @@
},
"outputs": [],
"source": [
"from mobilechelonian import Turtle\n",
"t = Turtle()\n",
"t.speed(10)\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"def box(units):\n",
" for i in range(4): #enter a value for range\n",
" # enter a value for range\n",
" for i in range(4): \n",
" t.forward(units)\n",
" t.right(90) #enter a degree value\n",
" # enter a degree value\n",
" t.right(90)\n",
"\n",
"for i in range(18): #360 degrees/20 degrees per iteration = 18 iterations\n",
" box(100) #enter a unit value\n",
"# 360 degrees/20 degrees per iteration = 18 iterations\n",
"for i in range(18):\n",
" # enter a unit value\n",
" box(100) \n",
" t.right(20)"
]
},
Expand All @@ -193,8 +222,8 @@
},
"outputs": [],
"source": [
"colours = [\"purple\", \"blue\", \"red\"] #this is a python list\n",
"colours[1] #indexing in python starts at \"0\", so to call \"red\" use \"0\" and so on."
"colours = [\"purple\", \"blue\", \"red\"] # this is a python list\n",
"colours[1] # indexing in python starts at \"0\", so to call \"red\" use \"0\" and so on."
]
},
{
Expand All @@ -205,9 +234,10 @@
},
"outputs": [],
"source": [
"#let's print what this looks like.\n",
"for i in range(18): #remember our loop with 18 iterations?\n",
" print(colours[i % 3], i % 3) #using the modulo operator leaves us with the remainder."
"# let's print what this looks like, remember our loop with 18 iterations?\n",
"for i in range(18): \n",
" # using the modulo operator leaves us with the remainder.\n",
" print(colours[i % 3], i % 3) "
]
},
{
Expand All @@ -218,20 +248,27 @@
},
"outputs": [],
"source": [
"#now let's put it all together\n",
"from mobilechelonian import Turtle\n",
"t = Turtle()\n",
"t.speed(10)\n",
"# now let's put it all together\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"def box(units):\n",
" for i in range(4): #enter a value for range\n",
" # enter a value for range\n",
" for i in range(4): \n",
" t.forward(units)\n",
" t.right(90) #enter a degree value\n",
" # enter a degree value\n",
" t.right(90) \n",
"\n",
"colours = [\"purple\", \"blue\", \"red\"] \n",
"for i in range(18):\n",
" t.pencolor(colours[i % 3]) #new turtle command\n",
" box(100) #enter a unit value\n",
" # new turtle command\n",
" t.pencolor(colours[i % 3]) \n",
" # enter a unit value\n",
" box(100) \n",
" t.right(20)"
]
},
Expand All @@ -258,9 +295,13 @@
"outputs": [],
"source": [
"### enter your code below. don't forget to import your turtle module!\n",
"from mobilechelonian import Turtle\n",
"t = Turtle()\n",
"t.speed(10)\n",
"import ColabTurtlePlus.Turtle as cTurtle \n",
"cTurtle.clearscreen()\n",
"cTurtle.setup(400, 400)\n",
"cTurtle.showborder()\n",
"t = cTurtle.Turtle()\n",
"t.speed(13)\n",
"\n",
"\n",
"def parallelogram(units): \n",
" for i in range(2):\n",
Expand All @@ -272,8 +313,10 @@
" \n",
"colours = [\"purple\", \"red\", \"blue\"] \n",
"for i in range(18):\n",
" t.pencolor(colours[i % 3]) #new turtle command\n",
" parallelogram(100) #enter a unit value\n",
" # new turtle command\n",
" t.pencolor(colours[i % 3]) \n",
" # enter a unit value\n",
" parallelogram(100) \n",
" t.right(20)"
]
},
Expand Down Expand Up @@ -308,7 +351,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 3b860c0

Please sign in to comment.