Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Turtle graphics

From Wikipedia, the free encyclopedia
Vector graphics using a relative cursor on a Cartesian plane
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Turtle graphics" – news ·newspapers ·books ·scholar ·JSTOR
(February 2008) (Learn how and when to remove this message)

Incomputer graphics,turtle graphics arevector graphics using a relativecursor (the "turtle") upon aCartesian plane (x and y axis). Turtle graphics is a key feature of theLogo programming language.[1] It is also a simple and didactic way of dealing withmoving frames.

Overview

[edit]
An animation that shows how the turtle is used to create graphics by combiningforward andturn commands while a pen is touching the paper
A spiral drawn with aniterative turtle graphics algorithm
A turtle graphic pattern drawn with aPython program

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 calleddown andup).

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 aLindenmayer system for generatingfractals.

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

History

[edit]

Turtle graphics are often associated with theLogo programming language.[2]Seymour Papert added support for turtle graphics to Logo in the late 1960s to support his version of theturtle 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) addressedCartesian geometry, being primarilyvector-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, thePython 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

[edit]
3D turtle graphics generated withCheloniidae Turtle Graphics
Pattern drawn with a Python program

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[5] implements the two vector approach; aroll 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 adive command is really a shorthand of a turn-roll-turn sequence.

Cheloniidae Turtle Graphics is a 3D turtle library forJava. It has abank command (same asroll) and apitch command (same asdive) in the "Rotational Cartesian Turtle". Other coordinate models, including non-Euclidean geometry, are allowed but not included.[6]

import turle turtle.bgcolor (black)turtle.pensize (2)def curv ():

          for i in range (500)              turtle.right (2)              turtle.forward (2)

turtle.speed (1)turtle.color ( "black ", "pink")turtle.begin_fill()turtle.left (140)turtle.forward (111.65)curve ()

turtle.left (120)curve ()turtle.forward (111.65)turtle.end_fill ()turtle.hideturtle ()

See also

[edit]
Animated gif with turtle in MSWLogo (Cycloid)[7]

References

[edit]
  1. ^Goldman, Ron; Schaefer, Scott; Ju, Tao."Turtle Geometry in Computer Graphics and Computer Aided Design"(PDF).CSE.WUSTL.edu.
  2. ^Thornburg, David D. (March 1983)."Friends of the Turtle: On Logo And Turtles".Compute!. p. 148. Retrieved6 October 2013.
  3. ^"25.1. turtle — Turtle graphics — Python 3.7.0 documentation".docs.python.org. Retrieved2018-08-23.
  4. ^"3. Hello, little turtles! — How to Think Like a Computer Scientist: Learning with Python 3".python.camden.rutgers.edu. Retrieved2018-08-23.
  5. ^Verhoeff, Tom (2010)."3D turtle geometry: artwork, theory, program equivalence and symmetry".International Journal of Arts and Technology.3 (2/3):288–319.doi:10.1504/IJART.2010.032569. Retrieved28 February 2021.
  6. ^Spencer Tipping on cheloniidae(retrieved 2016-9-17)
  7. ^Pietrocola, Giorgio (2005)."Tartapelago".Maecla.

Further reading

[edit]
Authority control databasesEdit this at Wikidata
Retrieved from "https://en.wikipedia.org/w/index.php?title=Turtle_graphics&oldid=1319341559"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp