{"id":987,"date":"2021-10-05T23:27:31","date_gmt":"2021-10-06T06:27:31","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=987"},"modified":"2021-10-05T23:27:31","modified_gmt":"2021-10-06T06:27:31","slug":"175-turtle-graphics-in-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/10\/175-turtle-graphics-in-python\/","title":{"rendered":"#175 Turtle graphics in python"},"content":{"rendered":"<p>#175 Turtle graphics in python<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport turtle\r\nfrom random import randint\r\n\r\ndef get_input_angle():\r\n    angle = 199\r\n    return angle\r\n\r\ndef generate_random_colour():\r\n    # Generates an R,G,B values randomly in range 0 to 255\r\n    r = randint(0, 255)\r\n    g = randint(0, 255)\r\n    b = randint(0, 255)\r\n    return r, g, b\r\n\r\nprint('Set up Screen')\r\nturtle.title('Colourful pattern')\r\nturtle.setup(640, 600)\r\nturtle.hideturtle()\r\nturtle.bgcolor('white')\r\n# Set the background colour of the screen\r\n# Indicates RGB numbers will be in the range 0 to 255\r\nturtle.colormode(255)\r\nturtle.speed(0)\r\n\r\nangle = get_input_angle()\r\n\r\nprint('Start the drawing')\r\nfor i in range(0, 600):\r\n    turtle.color(generate_random_colour())\r\n    turtle.forward(i)\r\n    turtle.right(angle)\r\n\r\nprint('Done')\r\nturtle.done()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex175.png?resize=625%2C579&#038;ssl=1\" alt=\"\" width=\"625\" height=\"579\" class=\"alignnone size-full wp-image-988\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex175.png 625w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex175-480x445.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 625px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#175 Turtle graphics in python import turtle from random import randint def get_input_angle(): angle = 199 return angle def generate_random_colour(): # Generates an R,G,B values randomly in range 0 to 255 r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) return r, g, b print(&#8216;Set up Screen&#8217;) turtle.title(&#8216;Colourful pattern&#8217;) turtle.setup(640, 600) turtle.hideturtle() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[2,13],"tags":[],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-python","category-turtle"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-fV","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":993,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/10\/177-random-snowflakes-using-python-turtle\/","url_meta":{"origin":987,"position":0},"title":"#177 Random snowflakes using python turtle","author":"gantovnik","date":"2021-10-06","format":false,"excerpt":"#177 Random snowflakes using python turtle [code language=\"python\"] import turtle from random import randint def generate_random_colour(): # Generates an R,G,B values randomly in range 0 to 255 r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) return r, g, b def setup_screen(title, background = 'white'): print('Set up\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex177.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex177.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex177.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":990,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/10\/176-the-koch-snowflake-using-python-turtle\/","url_meta":{"origin":987,"position":1},"title":"#176 The Koch snowflake using python turtle","author":"gantovnik","date":"2021-10-05","format":false,"excerpt":"#176 The Koch snowflake using python turtle import turtle # Set up Constants ANGLES = [60, -120, 60, 0] SIZE_OF_SNOWFLAKE = 300 def get_input_depth(): depth = 9 return depth def setup_screen(title, background='white', screen_size_x=640, screen_size_y=320, tracer_size=800): print('Set up Screen') turtle.title(title) turtle.setup(screen_size_x, screen_size_y) turtle.hideturtle() turtle.penup() turtle.backward(240) # Batch drawing to the screen\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex176.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":996,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/10\/178-fractal-tree-using-python-turtle\/","url_meta":{"origin":987,"position":2},"title":"#178 Fractal tree using python turtle","author":"gantovnik","date":"2021-10-06","format":false,"excerpt":"#178 Fractal tree using python turtle [code language=\"python\"] import turtle # Set up 'constants' # image size IMAGE_SIZE_X = 500 IMAGE_SIZE_Y = 500 # Determines depth of tree - try 2 and 1.25 as alternatives FACTOR = 1.45 def draw_tree(length, width=9): color = 'brown' if length < 1: return elif\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex178.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":269,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/circle-of-squares-using-turtle\/","url_meta":{"origin":987,"position":3},"title":"Circle of squares using turtle","author":"gantovnik","date":"2019-01-20","format":false,"excerpt":"[code language=\"python\"] import os import turtle os.chdir(r'D:\\projects\\wordpress\\ex51') os.getcwd() def draw_square(some_turtle): for i in range (1,5): some_turtle.forward(200) some_turtle.right(90) def draw_art(): #Turtle Brad n=5 brad = turtle.Turtle() brad.speed(10) for i in range(1,int(360\/n)+1): draw_square(brad) brad.right(n) draw_art() turtle.mainloop() [\/code] \u00a0 \u00a0","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"figure51","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/figure51.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/figure51.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/figure51.png?resize=525%2C300 1.5x"},"classes":[]},{"id":349,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/circle-of-diamonds-using-turtle\/","url_meta":{"origin":987,"position":4},"title":"Circle of diamonds using turtle","author":"gantovnik","date":"2019-01-26","format":false,"excerpt":"[code language=\"python\"] import os import turtle os.chdir(r'D:\\projects\\wordpress\\ex56') os.getcwd() def draw_diamond(some_turtle): some_turtle.left(30) some_turtle.forward(200) some_turtle.right(60) some_turtle.forward(200) some_turtle.right(120) some_turtle.forward(200) some_turtle.right(60) some_turtle.forward(200) some_turtle.right(150) def draw_art(): window = turtle.Screen() window.bgcolor(\"white\") brad = turtle.Turtle() brad.color(\"blue\") brad.speed(0) # Draw a circle with 36 diamonds. We rotate each diamond by 10 degrees at a time. for i in\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example56.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example56.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example56.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example56.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2865,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/439-relative-accelerometer-displacement-during-sine-vibration\/","url_meta":{"origin":987,"position":5},"title":"#439 Relative Accelerometer Displacement During Sine Vibration","author":"gantovnik","date":"2024-07-20","format":false,"excerpt":"\"If you want to find the secrets of the universe, think in terms of energy, frequency, and vibration.\" (Nikola Tesla) import math import numpy as np import matplotlib.pyplot as plt from scipy.optimize import fmin pi=math.pi f=6.0 # f, Hz T=1\/f #T, s omega=2.0*pi*f # Hz g=386.100 # in\/s^2 def func_a(angle,a0,phase):\u2026","rel":"","context":"In &quot;engineering&quot;","block_context":{"text":"engineering","link":"https:\/\/gantovnik.com\/bio-tips\/category\/engineering\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex439_abstract.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex439_abstract.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex439_abstract.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex439_abstract.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}