{"id":25796645,"url":"https://github.com/zentrocdot/unofficialturtlegraphicsdocs","last_synced_at":"2026-05-17T01:48:48.773Z","repository":{"id":279608782,"uuid":"939364546","full_name":"zentrocdot/UnofficialTurtleGraphicsDocs","owner":"zentrocdot","description":"Turtle Graphics Documentation","archived":false,"fork":false,"pushed_at":"2025-02-26T16:39:43.000Z","size":327,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T16:41:28.862Z","etag":null,"topics":["bash","python","python3","turtle-graphics"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zentrocdot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/color_names.txt","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"zentrocdot","thanks_dev":null,"custom":null}},"created_at":"2025-02-26T12:27:09.000Z","updated_at":"2025-02-26T16:39:46.000Z","dependencies_parsed_at":"2025-02-26T16:41:31.854Z","dependency_job_id":"6ebaaad5-4663-4b6f-9d16-13d870472d77","html_url":"https://github.com/zentrocdot/UnofficialTurtleGraphicsDocs","commit_stats":null,"previous_names":["zentrocdot/turtlegraphicsdocumentation","zentrocdot/inofficialturtlegraphicsdoc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentrocdot%2FUnofficialTurtleGraphicsDocs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentrocdot%2FUnofficialTurtleGraphicsDocs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentrocdot%2FUnofficialTurtleGraphicsDocs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentrocdot%2FUnofficialTurtleGraphicsDocs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zentrocdot","download_url":"https://codeload.github.com/zentrocdot/UnofficialTurtleGraphicsDocs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241024806,"owners_count":19896310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","python","python3","turtle-graphics"],"created_at":"2025-02-27T14:40:13.145Z","updated_at":"2026-05-17T01:48:48.722Z","avatar_url":"https://github.com/zentrocdot.png","language":"Python","funding_links":["https://buymeacoffee.com/zentrocdot"],"categories":[],"sub_categories":[],"readme":"I'm# Unofficial Turtle Graphics Docs\n\u003e [!NOTE]\n\u003e \u003cp align=\"justify\"\u003e🚧 Over time, this will be my personal\n\u003e Turtle Graphics documentation with how to instructions\n\u003e and tips and tricks. This is done alongside my programming\n\u003e activities.\u003c/p\u003e\n\n![banner_](https://github.com/user-attachments/assets/ede4d28d-f558-4869-94ab-bbe0fa017a9b)\n\n## 🐢 Turtle Graphics\n\n\u003cp align=\"justify\"\u003eThis documentation is related to the Python \nstandard turtle library [1].\u003c/p\u003e\n\n## 🚀 Getting Started\n\n\u003cp align=\"justify\"\u003eImport the standard Python module turtle \nto get started.\u003c/p\u003e\n\n```\nimport turtle\n```\n\n\u003cp align=\"justify\"\u003eAfter importing the standard Python \nmodule turtle one is ready to use Turtle Graphics for\ncreating images.\u003c/p\u003e\n\n## Setup Turtle Graphics Screen\n\n```\nscreen_x = 512\nscreen_y = 512\n\nsc = turtle.Screen()\nsc.setup(screen_x, screen_y)\n```\n\n\u003cp align=\"justify\"\u003eBased on my monitor which has a resolution\nof 1366 x 768 pixel I have chosen a square Turtle Graphics\nscreen with a resolution of 512 x 512 pixel. After initialising\nthe screen we will need the screen object sc no longer. The \nscreen setup is done at this point.\u003c/p\u003e\n\n## Setup Turtle Graphics Window\n\n```\nwindow_title = \"Turtle Graphics Demo\"\nbackground_color = \"red\"\n\nturtle.title(window_title)\nturtle.bgcolor(background_color)\n```\n\n\u003cp align=\"justify\"\u003eThis is changing the title of the Turtle\nGraphics window. The background color is also changed from\nwhite to red.\u003c/p\u003e\n\n## Putting the Things Together\n\n![image](https://github.com/user-attachments/assets/04e7ac38-9bd0-4693-8eb6-115bf8442e7c)\n\n\u003cp align=\"justify\"\u003eThe frame type for the drawing area we \ncan see is so-called sunken. At the top and at the left\nthere is a dark shadow. At the bottom and at the right\nthere is a light shadow.\u003c/p\u003e \n\n## Setup a Turtle Screen Object\n\n```\nts = turtle.Turtle()\n```\n\n\u003cp align=\"justify\"\u003eTo use Turtle Graphics one need a turtle\n(screen) object.\u003c/p\u003e \n\n## Add Background to the Window\n\n\u003cp align=\"justify\"\u003eFor adding a background to the window\none is using a canvas from tkinter. The rectangle canvas\nis what one needs for this goal.\u003c/p\u003e \n\n```\nbg_color = \"blue\"\nx0, y0 = -int(screen_x/2), -int(screen_y/2)\nx1, y1 = int(screen_x/2), int(screen_y/2)\n\ncs = ts.getscreen()\ntkwin = cs.getcanvas()\ntkwin.create_rectangle(x0, y0, x1, y1, width=0, outline=bg_color, fill=bg_color)\n```\n\n\u003cp align=\"justify\"\u003eBy adding a rectangle one can change\nthe background. The reason is explained later.\u003c/p\u003e \n\n## Putting the Things Together\n\n![image](https://github.com/user-attachments/assets/e2c6b664-2a42-40cd-bd7e-c98d6a0bbbbc)\n\n\u003cp align=\"justify\"\u003eIn this window we see something that\nwe should not see. The background is not completely blue\nas it should be. We see something like a border in red\nwhich is 2 point thick. This thin border in particular\ncauses difficulties later on.\u003c/p\u003e \n\n## Add a Background Correction to the Window\n\n```\nbg_color = \"blue\"\npad = 6\nx0, y0 = -int(screen_x/2)+pad, -int(screen_y/2)+pad\nx1, y1 = int(screen_x/2)-pad, int(screen_y/2)-pad\n\ncs = ts.getscreen()\ntkwin = cs.getcanvas()\ntkwin.create_rectangle(x0, y0, x1, y1, width=0, outline=bg_color, fill=bg_color)\n```\n\n\u003cp align=\"justify\"\u003eThis modifies the rectangle in a way,\nthat one has a two pixel border (plus 4 pixel)\naround the drawing area. The reason is explained later.\u003c/p\u003e \n\n## Putting the Things Together\n\n![image](https://github.com/user-attachments/assets/fbf745ff-9471-43b5-ba61-574e8eb805f5)\n\n\u003cp align=\"justify\"\u003eIf one inspects the behaviour of the frame\none sees that two sides show 2 pixel width and the other two\nsides 6 pixel width which should normally not happened. 2 sides\nshow a discrepancy of 4 pixels. Whether this is a Turtle Graphics\nerror or a Tkinter error is not yet clear.\u003c/p\u003e \n\n\u003cp align=\"justify\"\u003eOne result next to the later discussed problem is,\nthat an object is never centered in the screen.\u003c/p\u003e \n\n## Interactive Turtle Graphics\n\n\u003cp align=\"justify\"\u003eOpen a Python console and you can try out command in this console while a Turtle Graphics \nwindow is open.\u003c/p\u003e \n\n## Some Commands\n\n| METHOD              | PARAMETER   | DESCRIPTION |\n| :----------------- | :--------- | :--------- |\n| Turtle()\t          | None\t      | Creates and returns a new turtle object                                        |\n| home()              | None        | Move turtle to the origin (0,0)                                                |\n| forward(distance)   | amount      |\tMoves the turtle forward by the specified amount                               |\n| fd(distance)\t      | amount      |\tMoves the turtle forward by the specified amount                               |\n| backward(distance)  | amount\t    | Moves the turtle backward by the specified amount                              |\n| back(distance)\t    | amount\t    | Moves the turtle backward by the specified amount                              |\n| bk(distance)\t      | amount\t    | Moves the turtle backward by the specified amount                              |\n| right(angle)\t      | angle  \t    | Turns the turtle clockwise                                                     |\n| rt(angle)\t          | angle  \t    | Turns the turtle clockwise                                                     |\n| left(angle)         | angle\t      | Turns the turtle counter clockwise                                             |\n| lt(angle)           | angle\t      | Turns the turtle counter clockwise                                             |\n| penup()\t            | None\t      | Picks up the turtle’s Pen                                                      |\n| up()\t              | None\t      | Picks up the turtle’s Pen                                                      |\n| pendown()\t          | None\t      | Puts down the turtle’s Pen                                                     |\n| down()\t            | None\t      | Puts down the turtle’s Pen                                                     |\n| color(*args)\t      | color name  | Returns or sets pen color and fill color                                       |\n| pencolor(*args)\t    | color name  | Returns or sets pen color                                                      |\n| fillcolor(*args)    |\tcolor name  |\tReturns or sets the fill color                                                 |\n| heading()\t          | None\t      | Sets and returns the current heading                                           |\n| seth()\t            | None\t      | Sets and returns the current heading                                           |\n| position()\t        | None\t      | Returns the current position                                                   |\n| goto()\t            | x, y\t      | Moves the turtle to position x,y                                               |\n| begin_fill()        | None \t      | Remember the starting point for a filled polygon                               |\n| end_fill()\t        | None\t      | Closes the polygon and fills with the current fillcolor                        |\n| dot()\t              | None\t      | Prints a dot at the current position                                           |\n| stamp()\t            | None\t      | Prints an impression of a turtle shape at the current location                 |\n| shape()             | shapename\t  | Can be 'turtle', 'arrow', 'classic', 'circle', 'square', 'triangle' or 'blank' |\n| xcor()              | None        | Get the x-coordinate of the turtle                                             |\n| ycor()              | None        | Get the y-coordinate of the turtle                                             |\n\nNot working commands from the documentation:\n\n| METHOD       | PARAMETER  | DESCRIPTION |\n| :----------: | :--------: | :---------: |\n| teleport()   | x,y\t | Moves the turtle to position x,y without printing |\n\n## Turtle Version\n\nOne gets the turtle version by the command: \n\n\u003cpre\u003eprint(turtle._ver)\u003c/pre\u003e\n\nIn my case the result looks like:\n\n\u003cpre\u003eturtle 1.1b- - for Python 3.1   -  4. 5. 2009\u003c/pre\u003e\n\n## Radians Versus Degrees\n\n\u003cp align=\"justify\"\u003eTurn turtle right or turn turtle left can \nbe done by angle units. Angle units by default are in degrees,\nbut can be set via the degrees() or radians() functions to each\nother.\u003c/p\u003e \n\n## Pictures\n\n\u003cp align=\"justify\"\u003eOne can add pictures to the window. This is \ndone by the following command.\u003c/p\u003e \n\n\u003cpre\u003esc.bgpic(\"test.gif\")\u003c/pre\u003e\n\n![image](https://github.com/user-attachments/assets/1f6763fb-1079-4ef4-97a4-d1ae8d42eb39)\n\n## Colors\n\n\u003cp align=\"justify\"\u003eColors can be set using RGB color tuples\nlike (255, 0, 0) which is red. Names can be used like 'blue' \nor one can use a HEX representation like '#00FF00' which is\nlime.\u003c/p\u003e \n\n\n## Helper Functions\n\n### Color To RGB Function\n\nThis function needs the Python package webcolors. The goal\nis to return a color tuple from an arbitrary color input.\n\n```\n# -----------------------\n# Function color_to_rgb()\n# -----------------------\ndef color_to_rgb(color):\n    '''Color to RGB function.'''\n    # Try to get the RGB color.\n    try:\n        # Check the type of the color.\n        if color is not None:\n            if color.startswith('#'):\n                rgb = webcolors.hex_to_rgb(color)\n            elif color is None or isinstance(color, (list, tuple)):\n                rgb = color\n            elif isinstance(color, str):\n                rgb = webcolors.name_to_rgb(color)\n            # Get the RGB components.\n            r,g,b = rgb[0], rgb[1], rgb[2]\n        else:\n            r,g,b = 0,0,0\n    except:\n        r,g,b = 0,0,0\n    # Return the RGB color tuple.\n    return r,g,b\n```\n\n# References\n\n[1] https://docs.python.org/3/library/turtle.html\n\n[2] https://compform.net/turtles/\n\n[3] https://el.media.mit.edu/logo-foundation/what_is_logo/index.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentrocdot%2Funofficialturtlegraphicsdocs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzentrocdot%2Funofficialturtlegraphicsdocs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentrocdot%2Funofficialturtlegraphicsdocs/lists"}