Turtle graphics

In computer graphics, turtle graphics are vector graphics using a relative cursor (the "turtle") upon a Cartesian plane (x and y axis).

Uses your system voice; voice and rate in settings.

≈ 4 min read

Cite, export and learn8 citation formats · 8 exports · lesson and quiz

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer graphics, turtle graphics are vector graphics using a relative cursor (the "turtle") upon a Cartesian plane (x and y axis). Turtle graphics is a key feature of the Logo programming language. It is also a simple and didactic way of dealing with moving frames.

Overview

turtle graphics algorithm 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 Lindenmayer system for generating fractals.

Turtle geometry is also sometimes used in graphics environments as an alternative to a strictly coordinate-addressed graphics system.

History

Turtle graphics are often associated with the Logo programming language. Seymour Papert added support for turtle graphics to Logo in the late 1960s to support his version of the turtle robot, a simple robot controlled from the user's workstation that is designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot's body.

Turtle geometry works somewhat differently from (x,y) addressed Cartesian geometry, being primarily vector-based (i.e. relative direction and distance from a starting point) in comparison to coordinate-addressed systems such as bitmaps or raster graphics. As a practical matter, the use of turtle geometry instead of a more traditional model mimics the actual movement logic of the turtle robot.

The turtle is traditionally and most often represented pictorially either as a triangle or a turtle icon (though it can be represented by any icon). Today, the Python programming language's standard library includes a Turtle graphics module. 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.

Extension to three dimensions

generated with Cheloniidae Turtle Graphics 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 (normal vector) is defined to choose the plane the turtle's 2D "forward" vector rotates in; the "up" vector itself also rotates around the "forward" vector. In effect, the turtle has two different heading angles, one within the plane and the other determining the plane's angle.

Usually changing the plane's angle does not move the turtle, in line with the traditional setup. Verhoeff 2010 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.

Code example

The following Python code uses the turtle module to create a rainbow spiral: import turtle as t t.shape("turtle") x = 1 t.speed(10) colors = ["red", "orange", "yellow", "green", "blue", "purple"] for i in range(100): for i in colors: t.forward(x * 0.3) t.left(60) t.color(i) t.right(30.5) x = x + 1

See also

) Moving frame KTurtle L-system UCBLogo NetLogo FMSLogo MSWLogo Joy (programming language)

Text derived from https://en.wikipedia.org/w/index.php?oldid=1357730724 under CC BY-SA 4.0; modifications have been made.

Words in each sectionHistoryHistoryHistory: 223 words223Extension to three dime…Extension to three dimensionsExtension to three dimensions: 223 words223OverviewOverviewOverview: 183 words183Code exampleCode exampleCode example: 73 words73See alsoSee alsoSee also: 32 words32
Words in each section. Measured from the stored article body; sections below the minimum are not plotted.

Provenance

snapshot enwiki-001357730724 · captured 2026-06-04 · ledger · version history

Cite this page as: encyclopegia.org, “Turtle graphics”, snapshot enwiki-001357730724. https://encyclopegia.org/a/turtle-graphics

Sources cited in this revision

8 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.