{"id":5896,"date":"2024-06-20T02:11:00","date_gmt":"2024-06-20T06:11:00","guid":{"rendered":"https:\/\/www.both.org\/?p=5896"},"modified":"2024-06-15T22:28:36","modified_gmt":"2024-06-16T02:28:36","slug":"learning-with-the-turtle","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=5896","title":{"rendered":"Learning with the turtle"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"5896\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"has-small-font-size\">Image by: Patti Black on Unsplash<\/p>\n\n\n\n<p>Mathematics was anathema to me in my early years. As a visual learner, abstract concepts were challenging for me. However, in graduate school, I had to teach a fifth-grade student geometry using a unique curriculum involving Apple Logo and Turtle graphics. This experience changed my perspective on math.<\/p>\n\n\n\n<p>My transformative journey with Turtle graphics began about nine years ago when I serendipitously discovered the &#8216;Turtle&#8217; module for Python at a workshop. Python is readily available on most Linux distributions, so I eagerly embraced the Turtle. Learning to use the &#8216;turtle&#8217; module introduced me to Python and opened up a world of creativity and learning. I&#8217;ve been fortunate to share this journey with others, especially young people eager to create turtle graphics and explore the fascinating intersection of programming and mathematics.<\/p>\n\n\n\n<p>My first experiences with Python began in the terminal and the REPL (read eval print-loop).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/docsz\/AD_4nXfh3x8KpWGiP1G9PrUbCsjURK5XKa4a2EVd-eqY-eJvqWqsfxlf6r_UlfjlmlHYnxl1Y6RqilH_l-JTcPSWsdPvECQK4vij8wlnNfy6a-v_Y8GHfXyxNzHgg9ApZ0NshFub7eta1JIJyEdksKJ2nfzphm_7?key=l7XiDs_dzq6AuCTrXXAQcQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>I have used several development environments in my Python journey, including IDLE, VS-Codium, and VS Code. In this article, I am using <a href=\"https:\/\/vscodium.com\/\">VSCodium<\/a> on Linux.&nbsp;<\/p>\n\n\n\n<p>Keeping things simple, I begin with a simple program to draw a square. I need to add a couple of lines of code to keep the window open so I can show the students the code and they can see the graphical representation. I teach the students the importance of adding comments to their code, which helps them remember what each code block is for and explain what is happening to others they might be sharing their code with. Comments are denoted with the hash &#8216;#&#8217;<\/p>\n\n\n\n<p>That code is: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># This is the code to add the turtle library\nimport turtle\n\n# This is the code to add the drawing window\n\nwindow = turtle.Screen()\n\n# This is the code to close the drawing window\n\nwindow.exitonclick()\n<\/code><\/pre>\n\n\n\n<p>Next, I showed them how to draw a simple square using a turtle.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># This is the code to import the turtle function\n\nimport turtle\n\n# This is the code to open the drawing window\n\nwindow = turtle.Screen()\n\n# This is the code to draw the square\n\nturtle.forward(100)\nturtle.right(90)\nturtle.forward(100)\nturtle.right(90)\nturtle.forward(100)\nturtle.right(90)\nturtle.forward(100)\nturtle.right(90)\n\n# This is the code to close the window\n\nwindow.exitonclick()\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"578\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/06\/Square_drawing.png\" alt=\"\" class=\"wp-image-5910\" style=\"width:467px;height:auto\"\/><\/figure>\n\n\n\n<p>I show them how to simplify and iterate their code using a \u2018for\u2019 loop. The &#8216;for&#8217; loop produces the same square as illustrated above but with far less code. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># import the turtle function\nimport turtle\n\n# This is the code to open the drawing window\nwindow = turtle.Screen()\n\n# The range function to create the square\n\nfor x in range(4):\n   turtle.forward(100)\n   turtle.right(90)\n\n# This is the code to close the window\n\nwindow.exitonclick()\n<\/code><\/pre>\n\n\n\n<p>I show them how to give the \u2018turtle\u2019 different names and create more than one turtle. I introduce the students to objects and show them how to create a unique \u2018turtle\u2019 object using a name. In this case I will use the name \u2018jeff.\u2019 .&nbsp; All of these iterations produce the same figure illustrated above but are building blocks for later use. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># import the turtle function\n\nimport turtle\n\n# Create a separate turtle named jeff\n\njeff = turtle.Turtle()\n\n# This is the code to open the drawing window\n\nwindow = turtle.Screen()\n\nfor x in range(4):\n   jeff.forward(100)\n   jeff.right(90)\n\n# Code to close the drawing window \n\nwindow.exitonclick()<\/code><\/pre>\n\n\n\n<p>I demonstrate that we can create a simple square spiral by changing our code slightly.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># import the turtle function\n\nimport turtle\n\n# Code to open the drawing window\n\nwindow = turtle.Screen()\n\n# code to create a turtle with a name\n\njeff = turtle.Turtle()\n\n\nfor x in range(50):\n   jeff.forward(200)\n   jeff.right(92)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"792\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/06\/square-spiral.png\" alt=\"\" class=\"wp-image-5913\" style=\"width:399px;height:auto\"\/><\/figure>\n\n\n\n<p>I gradually introduced more complexity in each of the programming examples and then let the students&#8217; imaginations and nascent programming run wild. In the code below, I have added &#8216;color&#8217;, &#8216;pensize&#8217;, and &#8216;speed&#8217; iterations to the code, along with changing the range and the distance the &#8216;turtle&#8217; moves forward. The &#8216;speed&#8217; is set to zero, the fastest drawing speed available. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># import the turtle function\nimport turtle\n\n# code to create drawing window\n\nwindow = turtle.Screen()\n\n# Create a separate turtle object with colors and details\n\njeff = turtle.Turtle()\njeff.color(\"blue\")\njeff.pensize(3)\njeff.speed(0)\n\n\nfor x in range(50):\n   jeff.forward(200)\n   jeff.right(92)\n\n\nwindow.exitonclick()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"724\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/06\/Colored-Square-Spiral.png\" alt=\"\" class=\"wp-image-5916\" style=\"width:499px;height:auto\"\/><\/figure>\n\n\n\n<p>Many options within the &#8216;turtle&#8217; library provide many opportunities to work with beginning programmers. There are endless possibilities when you use Python and other open-source tools combined with your imagination and those of your students. Here&#8217;s one final code snippet that demonstrates more complex Python programming. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Draw a circle spiral with four colors\n\n# import the turtle function\n\nimport turtle\n\n# create the drawing window\n\nwindow = turtle.Screen()\n\n# set the drawing speed to zero which is the fastest\n\nturtle.speed(0)\n\n# list the colors in the circle spiral\n\ncolors = &#91;\"red\", \"brown\", \"blue\", \"green\"]\n\n\nfor x in range(100):\n    turtle.pencolor(colors&#91;x%4])\n    turtle.circle(x)\n    turtle.left(91)\n\n# close the drawing window\n\nwindow.exitonclick()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"892\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/06\/CircleSpiral.png\" alt=\"\" class=\"wp-image-5919\" style=\"width:471px;height:auto\"\/><\/figure>\n\n\n\n<p>Turtle graphics is not just a tool for executing commands but a gateway to encourage students to think procedurally and reflect on their thought processes. It provides instant visual feedback on code, allowing students to explore mathematical concepts and unleash creativity. You can easily see that Python Turtle graphics are a great example of open source&#8217;s power to provide an extremely affordable, world-class programming environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Image by: Patti Black on Unsplash Mathematics was anathema to me in my early years. As a visual<\/p>\n","protected":false},"author":32,"featured_media":5904,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5,150,238],"tags":[443,442],"class_list":["post-5896","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-programming","category-python","tag-mathematics","tag-turtle"],"modified_by":"Don Watkins","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5896"}],"version-history":[{"count":14,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5896\/revisions"}],"predecessor-version":[{"id":5974,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5896\/revisions\/5974"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/5904"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}