{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "3635e5d9", "metadata": {}, "outputs": [], "source": [ "# -*- coding: utf-8-sig -*-\n", "\n", "# Source: http://www.daniweb.com/software-development/python/code/216557/turtle-graphics-python\n", "# Official python-turtle documentation: http://docs.python.org/2/library/turtle.html\n", "\n", "from turtle import *\n", "import time\n", "\n", "speed(\"slowest\") #option 'fastest' will be handy for long iterations\n", "\n", "tracer(1) # only the nth screen update is shown. Set to 0 to turn tracer off.\n", "\n", "# The pen/turtle starts at the center (x=0, y=0) of the turtle display area by default.\n", "\n", "pencolor(\"green\")\n", "\n", "# While the pen is up, turtle can't draw; this is useful if you want the turtle to \n", "# go to a different location.\n", "\n", "penup()\n", "\n", "# Have the turtle go to the center of the screen\n", "goto(0,0)\n", "\n", "# put the pen down so the turtle can draw\n", "pendown()\n", "\n", "# Draw a circle with radius = 50 units. \n", "# The turtle doesn't draw the circle with its center at (0,0) however; it only draws\n", "# a circle that passes through the point (0,0).\n", "circle(50)\n", "\n", "time.sleep(2) # wait for 2 seconds\n", "\n", "# draw blue 100x100 squares\n", "pencolor(0.9,0.3,0.7) #(red,green,blue) triplet\n", "\n", "# At this point, by default, the turtle is facing east (right)\n", "for deg in range(0, 61, 20):\n", " \n", " right(90 + deg) # turn right by angle = 90 + deg\n", " \n", " forward(100) # step forward by 100 units while drawing a line\n", " \n", " right(90)\n", " \n", " forward(100)\n", " \n", " right(90)\n", " \n", " forward(100)\n", " \n", " right(90)\n", " \n", " forward(100)\n", " \n", " time.sleep(1)\n", " \n", " ps = pensize() # get curent size of pen\n", " \n", " pensize(ps + 1) # set new size of pen\n", " \n", "penup()\n", "\n", "goto(-150,-120)\n", "\n", "color(\"red\")\n", "\n", "write(\"Done!\")\n", "\n", "#IMPORTANT: if you don't do the following, the window might freeze\n", "done() \n", "\n", "#finally close the window to release the console\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2b7d677b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }