ArticleslgStudy

computer science

Turtle graphics

Turtle graphics is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Turtle graphics rather than just read about it. In short: 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.

Turtle graphics — main illustration
Turtle graphics — illustration

Key takeaways

  • Turtle graphics belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Turtle graphics to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Turtle graphics from memory before moving on to harder problems.

Reference excerpt

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

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

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:

See also

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

References

Further reading Papert, Seymour (1993). Mindstorms: Children, Computers, and Powerful Ideas (2nd ed.). New York: Basic Books. ISBN 0-465-04674-6. OCLC 794964988. Papert, Seymour (1993). The Children's Machine: Rethinking School in the Age of the Computer. New York: Basic Books. ISBN 0-465-01830-0. OCLC 248428992.

Illustrations

Turtle graphics: A spiral drawn with an iterative turtle graphics algorithm
A spiral drawn with an iterative turtle graphics algorithm
Turtle graphics: A turtle graphic pattern drawn with a Python program
A turtle graphic pattern drawn with a Python program
Turtle graphics: 3D turtle graphics generated with Cheloniidae Turtle Graphics
3D turtle graphics generated with Cheloniidae Turtle Graphics
Turtle graphics: Pattern drawn with a Python program
Pattern drawn with a Python program
Turtle graphics: Animated gif with turtle in MSWLogo (Cycloid)[8]
Animated gif with turtle in MSWLogo (Cycloid)[8]

Worked examples

Example 1 — a first encounter with Turtle graphics

Start with the simplest possible case. Write down what Turtle graphics claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Turtle graphics before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Turtle graphics ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Turtle graphics

In research
Turtle graphics appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Turtle graphics in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Turtle graphics is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer graphics, Free educational software, so understanding it makes those chapters shorter.
In everyday life
Look for Turtle graphics outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Turtle graphics in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Turtle graphics means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Turtle graphics out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Turtle graphics in simple terms?

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.

Why does Turtle graphics matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Turtle graphics?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Turtle graphics.

Tags

  • Computer graphics
  • Free educational software

Keep exploring