Turtle Graphics

Turtle graphics refers to a technique of allowing graphics to be drawn, typically on a computer screen, by controlling a virtual "turtle" with simple commands like forward and turn. Turtle graphics were first described using the programming language LOGO, and were created by Seymour Papert as part of constructivist approach to teaching kids geometry by creating simulation environments or "microworlds", where principles could be approached and explored in a direct way, as opposed to classical formal education using pre-determined abstractions. Turtle graphics are a kind of vector-based graphics system, in contrast to a traditional systems raster-based system like a bitmap. (See also wikipedia:Turtle Graphics)

Turtle Graphics Inkscape Extension[edit]

Installation[edit]

Unzip the two files contained in: File:Seymour.zip and copy them to ~/.config/inkscape/extensions[1]. Restart Inkscape if necessary.

Use[edit]

If properly installed, you should have a "Python" option in your Extensions menu. Select "Seymour..." to use the extension. Place your code in a text box on the SVG page and right-click the text to select "Object Properties" where you can set the id of the element to "code" (the value the Seymour extension expects).

Summary of turtle commands[edit]

Some commands have multiple versions (both fd and forward do the same thing)

Some extra's:

Styles

example:

 styles['fill'] = rgb(128, 128, 0)

Examples[edit]

Spiral[edit]

<source lang="python"> for i in range(45):

 pd()
 fd(100+i*10)
 lt(45)
 styles['stroke-width'] = i
 pu()

</source>

City[edit]

<source lang="python"> def building(h):

 pd()
 fd(10); lt(90)
 fd(h); lt(90)
 fd(10); lt(90)
 fd(h); lt(90)
 r = random.randint(0, 255)
 # styles is a python dictionary
 styles['fill'] = rgb(r,r,r)
 pu()

import random

def city():

 startgroup()
 for i in range(10):
   building(random.randint(10, 100))
   fd(10)
 endgroup()

def starcity():

 for i in range(10):
   city()
   lt(36)

goto(300, 200) face(0) building(100)

goto(300, 400) face(0) city()

goto(300, 800) face(0) starcity() </source>

Resources[edit]

Last modification 23 February 2012.