{"id":514,"date":"2023-02-28T09:00:05","date_gmt":"2023-02-28T09:00:05","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/?page_id=514"},"modified":"2023-02-28T09:05:23","modified_gmt":"2023-02-28T09:05:23","slug":"turtle","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-4\/turtle\/","title":{"rendered":"Turtle"},"content":{"rendered":"\n<p>Turtle is a built in Python package that allows you to set up a canvas and control a virtual pen to draw on it.<\/p>\n\n\n\n<p>The turtle package must be imported at the top of the program if you wish to use it. By default the turtle is ready to draw on a white canvas. If you wish to change the colour you can create a new screen. For example to make a grey canvas you use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>turtle.Screen().bgcolor(\"grey\")<\/code><\/pre>\n\n\n\n<p>You can then create a new instance of the Turtle class and start giving it directions using the class methods. These have easy to understand names such as penup(), pendown(), left(), right(), forward(), backward() and so on.<\/p>\n\n\n\n<p>Examine the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import turtle\n\nturtle.Screen().bgcolor(\"grey\")\n\nmyrtle = turtle.Turtle()\nmyrtle.penup()\nmyrtle.forward(90)\nmyrtle.left(45)\nmyrtle.pendown()\n\ndef branch():\n    for i in range(3):\n        for i in range(3):\n            myrtle.forward(30)\n            myrtle.backward(30)\n            myrtle.right(45)\n        myrtle.left(90)\n        myrtle.backward(30)\n        myrtle.left(45)\n    myrtle.right(90)\n    myrtle.forward(90)\n\nfor i in range(8):\n    branch()\n    myrtle.left(45)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"484\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/02\/28090126\/Py32-1024x484.png\" alt=\"\" class=\"wp-image-517\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/02\/28090126\/Py32-1024x484.png 1024w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/02\/28090126\/Py32-300x142.png 300w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/02\/28090126\/Py32-768x363.png 768w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/02\/28090126\/Py32.png 1104w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Turtle output<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"nextlink\"><a href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-4\/challenge-10\/\" data-type=\"page\" data-id=\"520\">Next: Challenge 10<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Turtle is a built in Python package that allows you to set up a canvas and control a virtual pen to draw on it. The turtle package must be imported at the top of the program if you wish to use it. By default the turtle is ready to draw on a white canvas. If&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-4\/turtle\/\">Continue reading <span class=\"screen-reader-text\">Turtle<\/span><\/a><\/p>\n","protected":false},"author":5710,"featured_media":0,"parent":20,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-514","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":3,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/514\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/514\/revisions\/522"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/20"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/media?parent=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}