{"id":17344,"date":"2020-11-09T21:02:32","date_gmt":"2020-11-09T21:02:32","guid":{"rendered":"https:\/\/holypython.com\/?page_id=17344"},"modified":"2021-04-01T14:36:16","modified_gmt":"2021-04-01T14:36:16","slug":"turtle-stars","status":"publish","type":"page","link":"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-stars\/","title":{"rendered":"Turtle Stars"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"17344\" class=\"elementor elementor-17344\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-38819ef elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"38819ef\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-98d652e\" data-id=\"98d652e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-076d8a2 elementor-widget elementor-widget-text-editor\" data-id=\"076d8a2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ol><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-penup-and-pendown\/\">Turtle <b>Penup<\/b>\u00a0&amp; <b>Pendown<\/b><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-positioning-goto-setpos-setx-sety-setheading\/\">Turtle Positioning: <b>goto<\/b>, <b>setpos<\/b>, <b>setx<\/b>, <b>sety<\/b>, <b>setheading<\/b><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-hideturtle-showturtle\/\">Turtle <b>hideturtle, <\/b>\u00a0<b>showturtle<\/b><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-speed\/\">Turtle <b>Speed<\/b><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-fill\/\">Turtle <b>Fill<\/b><\/a><\/li><li><a style=\"background-color: #ffffff;\" href=\"https:\/\/holypython.com\/turtle-recap-for-learning-python-programming-essentials\/\">Learn Python with Turtle<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-rotating-rectangles\/\">Turtle Rotating Rectangles<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-turbines\/\">Turtle Turbines<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-spirals\/\">Turtle Spirals<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-stars\/\">Turtle Stars<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-constellations\/\">Turtle Constellations<\/a><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-820bd33\" data-id=\"820bd33\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-2eacc4c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2eacc4c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-1d7add4\" data-id=\"1d7add4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3ce197a elementor-widget elementor-widget-heading\" data-id=\"3ce197a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\">Turtle Stars<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-3a3ccc8\" data-id=\"3a3ccc8\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-57329d4 elementor-widget elementor-widget-raven-image\" data-id=\"57329d4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"raven-image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"raven-image\">\n\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\n\t\t\n\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"263\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds-300x263.jpg\" class=\"attachment-medium size-medium wp-image-17371\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds-300x263.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds-768x673.jpg 768w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds.jpg 890w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/>\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Drawing Stars with Turtle<\/figcaption>\n\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-98a498b elementor-widget elementor-widget-text-editor\" data-id=\"98a498b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Contents<\/p><ol><li><a href=\"#intro\">Introduction<\/a><\/li><li><span style=\"outline-width: 0px !important; user-select: auto !important;\"><a href=\"#geo\">Star Geometry<\/a><\/span><\/li><li><a style=\"background-color: #ffffff; outline-width: 0px !important; user-select: auto !important;\" href=\"#example1\">Example 1: One simple star<\/a><\/li><li><a href=\"#example2\">Example 2: Yellow star<\/a><\/li><li><a href=\"#example4\">Example 3: Dark Blue Night Background<\/a><\/li><li><a href=\"#example4\">Example 4: Multiple Stars<\/a><\/li><li><a href=\"#example5\">Example 5: Multiple Multi-color Stars<\/a><\/li><li><a href=\"#resource\">Resources<\/a><\/li><li><a style=\"background-color: #ffffff;\" href=\"#sum\">Summary<\/a><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b3f3750 elementor-widget elementor-widget-menu-anchor\" data-id=\"b3f3750\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"intro\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e653fb5 elementor-widget elementor-widget-text-editor\" data-id=\"e653fb5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Introduction<\/h2><p>Drawing with turtle library of Python can be very educational and fun.<\/p><p>In this tutorial we will focus on how to draw stars with turtle in Python.<\/p><p>We&#8217;re going to show you how to draw monocolor stars such as yellow stars as well as how to draw multicolor stars.<\/p><p>Then we will attempt to scatter a number of stars on a dark blue night sky using turtle drawing and Python. Let&#8217;s see.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-987e8d5 elementor-widget elementor-widget-menu-anchor\" data-id=\"987e8d5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"geo\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2dfe85c elementor-widget elementor-widget-text-editor\" data-id=\"2dfe85c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Star Geometry<\/h2><p>So how can we draw a perfect star with code in Python? It turns out a star polygon or in this case a star pentagon specifically has 5 sides with external angle of 144 on each side (internal angle of 36 degrees).<\/p><ul><li>Let&#8217;s start with importing turtle library first.<ul><li><code>import turtle<\/code><\/li><\/ul><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-d68ec74 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d68ec74\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-dbd7f96\" data-id=\"dbd7f96\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-eda9a44 elementor-widget elementor-widget-image\" data-id=\"eda9a44\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"640\" height=\"652\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_angle.jpg\" class=\"attachment-full size-full wp-image-17369\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_angle.jpg 640w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_angle-294x300.jpg 294w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Drawing a star (with external angle of 144 degrees)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-253e045\" data-id=\"253e045\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bde41ad elementor-widget elementor-widget-image\" data-id=\"bde41ad\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"890\" height=\"780\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds.jpg\" class=\"attachment-full size-full wp-image-17371\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds.jpg 890w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds-300x263.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_3_rounds-768x673.jpg 768w\" sizes=\"(max-width: 890px) 100vw, 890px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Drawing a star with turtle<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-33bb751 elementor-widget elementor-widget-text-editor\" data-id=\"33bb751\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-size: 17px;\">This makes everything so much easier as we love repetition in coding. Only 5 iterations with same turn angles will do.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d1e3143 elementor-widget elementor-widget-menu-anchor\" data-id=\"d1e3143\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example1\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-97a84a5 elementor-widget elementor-widget-text-editor\" data-id=\"97a84a5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Example 1: One Simple Star<\/h3><p>After opening an image you can use the .resize() method on it to create a new image with a new size.<\/p><p><u>Please Note<\/u>: Adding <code>turtle.exitonclick()<\/code> can help terminate turtle window once you&#8217;re done with your turtle drawing or observations. If you don&#8217;t add this little code piece, turtle tends to freeze which requires a kernel restart which can be annoying. So we will add it to the end of each code and you&#8217;re also advised to do so.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5b3c326 elementor-widget elementor-widget-html\" data-id=\"5b3c326\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import turtle\n\nfor i in range(5):\n    turtle.forward(150)\n    turtle.right(144)\n\nturtle.exitonclick()\n<\/pre><\/code>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ea0653 elementor-widget elementor-widget-text-editor\" data-id=\"0ea0653\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-size: 17px;\">Here is turtle in action. We figured out a single star. Yay! <\/span><\/p><p><span style=\"font-size: 17px;\">It&#8217;s downhill from this point. Now we can add some spice. Maybe some colors. And definitely some more stars so they don&#8217;t feel lonely \ud83d\ude09<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-933ac8a elementor-widget elementor-widget-image\" data-id=\"933ac8a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"374\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/turtle_star2.gif\" class=\"attachment-full size-full wp-image-17375\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Turtle in action (Drawing a single star)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8458196 elementor-widget elementor-widget-menu-anchor\" data-id=\"8458196\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example2\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-84924b4 elementor-widget elementor-widget-text-editor\" data-id=\"84924b4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Example 2: Yellow Star<\/h3><p>We can simply use .color method to give turtle a color: <code style=\"font-size: 15.3px; background-color: #ffffff;\">turtle.color(\"yellow\")<\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b73accc elementor-widget elementor-widget-html\" data-id=\"b73accc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import turtle\nturtle.color(\"yellow\")\n\nfor i in range(5):\n    turtle.forward(150)\n    turtle.right(144)\n    \nturtle.exitonclick()\n<\/pre><\/code>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d0ae95d elementor-widget elementor-widget-image\" data-id=\"d0ae95d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"426\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow.jpg\" class=\"attachment-full size-full wp-image-17397\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow.jpg 586w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow-300x218.jpg 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Yellow Star (Drawing a single star in color)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7aa9ad1 elementor-widget elementor-widget-text-editor\" data-id=\"7aa9ad1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Great now our star has some color even. We can also transform the background to a color like dark blue which will make the star&#8217;s yellow pop better.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-83160bb elementor-widget elementor-widget-menu-anchor\" data-id=\"83160bb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example3\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bbc24b9 elementor-widget elementor-widget-text-editor\" data-id=\"bbc24b9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Example 3: Dark Blue Night Sky<\/h3><p>We can use .bgcolor method to change the background color of a turtle drawing window: <code style=\"font-size: 15.3px; background-color: #ffffff;\">turtle.bgcolor(\"darkblue\")<\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-caeae59 elementor-widget elementor-widget-html\" data-id=\"caeae59\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import turtle\nturtle.color(\"yellow\")\nturtle.bgcolor(\"darkblue\")\n\nfor i in range(5):\n    turtle.forward(150)\n    turtle.right(144)\n    \nturtle.exitonclick()\n<\/pre><\/code>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b26cdb8 elementor-widget elementor-widget-image\" data-id=\"b26cdb8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"431\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow_at_night_sky.jpg\" class=\"attachment-full size-full wp-image-17398\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow_at_night_sky.jpg 511w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_yellow_at_night_sky-300x253.jpg 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Yellow Star (Drawing a single star in color)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b70f99 elementor-widget elementor-widget-text-editor\" data-id=\"9b70f99\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Perfect. On your computer it might look even better actually. On the website it&#8217;s being scaled up which makes the resolution appear worse than it is.<\/p><p>Now, let&#8217;s find a cure for loneliness.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-03418a9 elementor-widget elementor-widget-menu-anchor\" data-id=\"03418a9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example4\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c1494b4 elementor-widget elementor-widget-text-editor\" data-id=\"c1494b4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Example 4: Multiple Stars<\/h3><p>turtle&#8217;s <code>setpos()<\/code> or <code>goto()<\/code> methods can be used to make the cursor travel between different coordinates and this way we can draw a different star at each coordinate. We will have to adjust a few things:<\/p><ul><li>Let&#8217;s turn down the star size quite a bit. This can be easily adjusted by passing a smaller value to <code>.forward()<\/code> command which draws each side of the star.<\/li><li>We can implement a random.randint() structure which tells a random x,y coordinate on our pseudosky.<\/li><li>Also, let&#8217;s speed up the turtle so we don&#8217;t have to wait too long for each star to be drawn. This can be achieved with <code>turtle.speed(0)\u00a0<\/code><ul><li>0 : fastest setting while<\/li><li>10 : slowest setting<\/li><\/ul><\/li><li>Finally, I have a feeling that if we put our star drawing algorithm in a user defined function everything will be less messier.<\/li><li>By the way, let&#8217;s also hide the turtle for a smoother example. This can be done with <code>turtle.hideturtle()<\/code><\/li><\/ul><p>Let&#8217;s try. Here is the Python code.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-77c0dc0 elementor-widget elementor-widget-html\" data-id=\"77c0dc0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import turtle\nturtle.color(\"yellow\")\nturtle.bgcolor(\"darkblue\")\nturtle.speed(0)\nturtle.hideturtle()\n\ndef starmaker(step,angle):\n    for iter in range(5):\n        turtle.forward(step)\n        turtle.right(angle)\n    \nfor i in range(10):\n    turtle.penup()\n    turtle.setpos(random.randint(-350, 350), random.randint(100, 300))\n    turtle.pendown()\n    starmaker(10,144)\n\nturtle.exitonclick()\n<\/pre><\/code>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3eb6725 elementor-widget elementor-widget-text-editor\" data-id=\"3eb6725\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>And, here is the result.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-01272ff elementor-widget elementor-widget-image\" data-id=\"01272ff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1852\" height=\"972\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/star_animation3.gif\" class=\"attachment-full size-full wp-image-17727\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Yellow Star on a Dark Blue Night Sky in Turtle Graphics with Python<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a2bca3c elementor-widget elementor-widget-text-editor\" data-id=\"a2bca3c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Wow! Now we&#8217;re talking. Our turtle drawing is starting to look legit. It might even compete with Van Gogh&#8217;s Starry Night, what do you think? Alright, I think that&#8217;s an exaggeration too too. But it&#8217;s still pretty good for turtle digital art category.<\/p><p>Where can we go from here? Well, rather than a solid yellow, stars kind of flicker\u00a0. Maybe we can draw stars with multiple colors just for fun?<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e12b06b elementor-widget elementor-widget-menu-anchor\" data-id=\"e12b06b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example5\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f3cc9d7 elementor-widget elementor-widget-text-editor\" data-id=\"f3cc9d7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Example 5: Multi-color Multiple Stars<\/h3><p>So, how can we make each side of the star a different random color? Pretty easy actually.<\/p><p>By placing <code>turtle.color()<\/code> attribute inside the turtle making function&#8217;s for loop, we can make sure turle&#8217;s color is redefined at each iteration.<\/p><p>We can also create a list of predefined colors. Then using random library we can pick a random color by randomly accessing the indexes of this color list. Remember that list index starts at 0 in Python so <code>random.randint()<\/code> should go to <b>list size-1<\/b> at maximum.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0b0704e elementor-widget elementor-widget-html\" data-id=\"0b0704e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import turtle\n\nturtle.bgcolor(\"darkblue\")\nturtle.speed(0)\nturtle.hideturtle()\n\ncolor_lst=[\"red\", \"orange\", \"cyan\", \"yellow\", \"gray\", \"lightgreen\"]\n\ndef starmaker(step,angle):\n    for iter in range(5):\n        turtle.color(color_lst[random.randint(0,5)])\n        turtle.forward(step)\n        turtle.right(angle)\n\nfor i in range(15):\n    turtle.penup()\n    turtle.setpos(random.randint(-350, 350), random.randint(100, 300))\n    turtle.pendown()\n    starmaker(10,144)\n    \nturtle.exitonclick()\n<\/pre><\/code>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3831259 elementor-widget elementor-widget-image\" data-id=\"3831259\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1841\" height=\"981\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor.jpg\" class=\"attachment-full size-full wp-image-17436\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor.jpg 1841w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor-300x160.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor-1024x546.jpg 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor-768x409.jpg 768w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/11\/starry_night_multicolor-1536x818.jpg 1536w\" sizes=\"(max-width: 1841px) 100vw, 1841px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Yellow Star on a Dark Blue Night Sky in Turtle Graphics with Python<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fb212a6 elementor-widget elementor-widget-text-editor\" data-id=\"fb212a6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here we go we started with a single black &amp; white star and discovered all the way up to multiple little stars with multiple colors on a dark blue night sky.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-acd0f14 elementor-widget elementor-widget-menu-anchor\" data-id=\"acd0f14\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"sum\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4d63e63 elementor-widget elementor-widget-text-editor\" data-id=\"4d63e63\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Resources<\/h3><p>You can check out other turtle tutorials we have for more examples and turtle knowledge.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-99c8204 elementor-widget elementor-widget-text-editor\" data-id=\"99c8204\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Recommended Turtle Tutorials:<\/b><\/p><ol><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-speed\/\">Turtle Speed<\/a><\/li><li><a style=\"background-color: #ffffff;\" href=\"https:\/\/holypython.com\/turtle-recap-for-learning-python-programming-essentials\/\">Learn Python with Turtle<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-rotating-rectangles\/\">Turtle Rotating Rectangles<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-turbines\/\">Turtle Turbines<\/a><\/li><li><a href=\"https:\/\/holypython.com\/turtle-spirals\/\">Turtle Spirals<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-stars\/\">Turtle Stars<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-turtle-tutorial\/turtle-constellations\/\">Turtle Constellations<\/a><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c18c33b elementor-widget elementor-widget-menu-anchor\" data-id=\"c18c33b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"sum\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-79e5d4d elementor-widget elementor-widget-text-editor\" data-id=\"79e5d4d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Summary<\/h3><p>In this <a href=\"https:\/\/holypython.com\">Python Tutorial<\/a>, we have learned how to draw stars with turtle.<\/p><p>We have also advanced the simple idea of drawing a star and played with it a litte. We ended up drawing multiple good looking stars on a night sky.<\/p><p>This tutorial can be a great practice to demonstrate basic Python concepts. Feel free to freely use and share at your school or work, <b>attributions or source credit are very welcome.<\/b><\/p><p>Thank you for your support!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Turtle Penup\u00a0&amp; Pendown Turtle Positioning: goto, setpos, setx, sety, setheading Turtle hideturtle, \u00a0showturtle Turtle Speed Turtle Fill Learn Python with Turtle Turtle Rotating Rectangles Turtle Turbines Turtle Spirals Turtle Stars Turtle Constellations Turtle Stars Drawing Stars with Turtle Contents Introduction Star Geometry Example 1: One simple star Example 2: Yellow star Example 3: Dark Blue [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":16389,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"full-width.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-17344","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/17344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=17344"}],"version-history":[{"count":0,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/17344\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/16389"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=17344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}