Turtle graphics
This article needs additional citations for verification. (February 2008) |
In
Overview



The turtle has three attributes: a location, an orientation (or direction), and a pen. The pen, too, has attributes: color, width, and on/off state (also called down and up).
The turtle moves with commands that are relative to its own position, such as "move forward 10 spaces" and "turn left 90 degrees". The pen carried by the turtle can also be controlled, by enabling it, setting its color, or setting its width. A student could understand (and predict and reason about) the turtle's motion by imagining what they would do if they were the turtle. Seymour Papert called this "body syntonic" reasoning.
A full turtle graphics system requires control flow, procedures, and recursion: many turtle drawing programs fall short. From these building blocks one can build more complex shapes like squares, triangles, circles and other composite figures. The idea of turtle graphics, for example is useful in a
History
Turtle graphics are often associated with the
Today, the Python programming language's standard library includes a Turtle graphics module.[3] Like its Logo predecessor, the Python implementation of turtle allows programmers to control one or more turtles in a two-dimensional space. Since the standard Python syntax, control flow, and data structures can be used alongside the turtle module, turtle has become a popular way for programmers learning Python to familiarize themselves with the basics of the language.[4]
Extension to three dimensions


The ideas behind turtle graphics can be extended to include three-dimensional space. This is achieved by using one of several different coordinate models. A common setup is cartesian-rotational as with the original 2D turtle: an additional "up" vector (
Verhoeff 2010[5] implements the two vector approach; a roll command is used to rotate the "up" vector around the "forward" vector. The article proceeds to develop an algebraic theory to prove geometric properties from syntactic properties of the underlying turtle programs. One of the insights is that a dive command is really a shorthand of a turn-roll-turn sequence.
Cheloniidae Turtle Graphics is a 3D turtle library for Java. It has a bank command (same as roll) and a pitch command (same as dive) in the "Rotational Cartesian Turtle". Other coordinate models, including non-Euclidean geometry, are allowed but not included.[6]
Code example
The following Python code uses the turtle module to create a rainbow spiral:
import turtle
tina = turtle.Turtle()
tina.shape("turtle")
x = 1
tina.speed(10000)
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
for i in range(100):
for i in colors:
tina.forward(x * 0.3)
tina.left(60)
tina.color(i)
tina.right(30.5)
x = x + 1
See also

References
- ^ Goldman, Ron; Schaefer, Scott; Ju, Tao. "Turtle Geometry in Computer Graphics and Computer Aided Design" (PDF). CSE.WUSTL.edu.
- ^ Thornburg, David D. (March 1983). "Friends of the Turtle: On Logo And Turtles". Compute!. p. 148. Retrieved 6 October 2013.
- ^ "25.1. turtle — Turtle graphics — Python 3.7.0 documentation". docs.python.org. Retrieved 2018-08-23.
- ^ "3. Hello, little turtles! — How to Think Like a Computer Scientist: Learning with Python 3". python.camden.rutgers.edu. Retrieved 2018-08-23.
- . Retrieved 28 February 2021.
- ^ Spencer Tipping on cheloniidae(retrieved 2016-9-17)
- ^ Pietrocola, Giorgio (2005). "Tartapelago". Maecla.
Further reading
- OCLC 794964988.
- Papert, Seymour (1993). The Children's Machine: Rethinking School in the Age of the Computer. New York: Basic Books. OCLC 248428992.