This is a very simple introduction to Turtle graphics. The turtle starts in the middle of the window, moves forward a small distance, turns right, moves forward a slightly longer distance, right again, even further this time… until the distance equals or exceeds a given limit.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an import turtle, give it the command turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.right(25), and it rotates in-place 25 degrees clockwise.
# Spiral outwards in an ever-expanding square # using Turtle graphics # https://docs.python.org/3/library/turtle.html # Authour: Alan Richmond, Python3.codes from turtle import * lineLen = inc = 20 # Line starts this long, grows this much max = 800 # until it's this long turn = 90 # try different numbers, e.g. 120 # The line grows longer until it fills the window while lineLen &lt; max: # https://docs.python.org/3/library/turtle.html#turtle.forward forward(lineLen) # https://docs.python.org/3/library/turtle.html#turtle.right right (turn) lineLen += inc # https://docs.python.org/3/library/turtle.html#turtle.done done()
[welcomewikilite wikiurl=”http://en.wikipedia.org/wiki/Turtle_graphics” sections=”Overview” settings=””]