{"id":293,"date":"2017-05-25T05:03:46","date_gmt":"2017-05-25T05:03:46","guid":{"rendered":"https:\/\/www.triptera.com.au\/wordpress\/?p=293"},"modified":"2017-05-27T09:56:25","modified_gmt":"2017-05-27T09:56:25","slug":"coderdojo-turtle-racing-1-oval-track","status":"publish","type":"post","link":"https:\/\/www.triptera.com.au\/wordpress\/2017\/05\/25\/coderdojo-turtle-racing-1-oval-track\/","title":{"rendered":"CoderDojo turtle racing &#8211; 1 &#8211; oval track"},"content":{"rendered":"<p>This is a fun task to play with Python&#8217;s turtle graphics. Below is Python code to draw a race track. See if you can write some Python code between &#8220;# ninja start&#8221; and &#8220;# ninja end&#8221; which will make the turtle race all the way around the track without bumping into the side of the track. I have provided the first three lines which gets the turtle half way around the first turn.<\/p>\n<p><a href=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-294\" src=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example-300x218.png\" alt=\"\" width=\"300\" height=\"218\" srcset=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example-300x218.png 300w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example-768x557.png 768w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example-500x363.png 500w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/05\/oval_example.png 962w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The python commands you will need are<\/p>\n<pre class=\"brush: python; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nracer.forward(100)\u00a0# move in a straight line 100 pixels\r\nracer.left(45)     # turn 45 degrees to the left\r\nracer.right(45)    # turn 45 degrees to the right\r\n<\/pre>\n<p>You can change the numbers to whatever values you need to get the turtle all the way around the track.<\/p>\n<p>You can run this python code on your computer or on website such as <a href=\"https:\/\/hourofpython.trinket.io\/a-visual-introduction-to-python\">https:\/\/hourofpython.trinket.io<\/a> .<\/p>\n<p>Here is the python code to run and edit<\/p>\n<pre class=\"brush: python; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n# Turtle racing track = oval track\r\n# Don't edit the lines for turtle &quot;track&quot;\r\n# Edit the lines for turtle &quot;racer&quot;\r\n# between &quot;# ninja start&quot; and &quot;# ninja end&quot;\r\n# See if you can find the fastest way around the track\r\n# Make sure the turtle doesn't touch the sides\r\n\r\nimport turtle\r\n\r\n# turtle which draws track\r\ntrack = turtle.Turtle()\r\ntrack.speed(0)\r\ntrack.color(&quot;black&quot;)\r\ntrack.penup()\r\ntrack.hideturtle()\r\n\r\n# inside of track\r\ntrack.goto(-50,-100)\r\ntrack.pendown()\r\ntrack.forward(100)\r\ntrack.circle(100,180)\r\ntrack.forward(100)\r\ntrack.circle(100,180)\r\ntrack.penup()\r\n\r\n# outside of track\r\ntrack.goto(-50,-150)\r\ntrack.pendown()\r\ntrack.forward(100)\r\ntrack.circle(150,180)\r\ntrack.forward(100)\r\ntrack.circle(150,180)\r\ntrack.penup()\r\n\r\n# turtle which races around track\r\nracer = turtle.Turtle()\r\nracer.shape(&quot;turtle&quot;)\r\nracer.color(&quot;blue&quot;)\r\nracer.speed(10)\r\n\r\n# set up racer at start line\r\nracer.penup()\r\nracer.goto(0,-125)\r\nracer.pendown()\r\n\r\n# ninja start\r\n# python code to race around track\r\n# example code shows first three straight lines\r\nracer.forward(100)\r\nracer.left(45)\r\nracer.forward(100)\r\nracer.left(45)\r\nracer.forward(100)\r\n# ninja end\r\n\r\n<\/pre>\n<p>NEXT: <a href=\"https:\/\/www.triptera.com.au\/wordpress\/?p=302\">CoderDojo turtle racing &#8211; 2 &#8211; oval track with scoring<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a fun task to play with Python&#8217;s turtle graphics. Below is Python code to draw a race track. See if you can write some Python code between &#8220;# ninja start&#8221; and &#8220;# ninja end&#8221; which will make the turtle race all the way around the track without bumping into the side of the [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-coderdojo"],"_links":{"self":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":12,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/293\/revisions\/357"}],"wp:attachment":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}