# Turtle graphics

Some simple "turtle graphics" functions are included. Functions to control the turtle begin with a capital letter: Forward, Turn, Circle, Orientation, Rectangle, Pendown, Penup, Pencolor, Penwidth, and Reposition.

``````using Luxor

Drawing(1200, 1200, "/tmp/turtles.png")
origin()
background("black")

# let's have two turtles
raphael = Turtle(0, 0, true, 0, (1.0, 0.25, 0.25)) ; michaelangelo = Turtle(0, 0, true, 0, (1.0, 0.25, 0.25))

setopacity(0.95)
setline(6)

Pencolor(raphael, 1.0, 0.4, 0.2);       Pencolor(michaelangelo, 0.2, 0.9, 1.0)
Reposition(raphael, 500, -200);         Reposition(michaelangelo, 500, 200)
Message(raphael, "Raphael");            Message(michaelangelo, "Michaelangelo")
Reposition(raphael, 0, -200);           Reposition(michaelangelo, 0, 200)

pace = 10
for i in 1:5:400
for turtle in [raphael, michaelangelo]
Circle(turtle, 3)
HueShift(turtle, rand())
Forward(turtle, pace)
Turn(turtle, 30 - rand())
Message(turtle, string(i))
pace += 1
end
end

finish()
preview()``````
``Turtle(xpos=0, ypos=0, pendown=true, orientation=0, pencolor=(1.0, 0.25, 0.25))``

With a Turtle you can command a turtle to move and draw: turtle graphics.

The functions that start with a capital letter are: Forward, Turn, Circle, Orientation, Rectangle, Pendown, Penup, Pencolor, Penwidth, and Reposition.

There are also some other functions. To see how they might be used, see Lindenmayer.jl.

source
``Forward(t::Turtle, d)``

Move the turtle forward by `d` units. The stored position is updated.

source
``Turn(t::Turtle, r)``

Increase the turtle's rotation by `r` degrees. See also `Orientation`.

source
``Circle(t::Turtle, radius)``

Draw a filled circle centred at the current position with the given radius.

source
``HueShift(t::Turtle, inc = 1)``

Shift the Hue of the turtle's pen forward by `inc`.

source
``Message(t::Turtle, txt)``

Write some text at the current position.

source
``Orientation(t::Turtle, r)``

Set the turtle's orientation to `r` degrees. See also `Turn`.

source
``Randomize_saturation(t::Turtle)``

Randomize saturation of the turtle's pen color.

source
``Rectangle(t::Turtle, width, height)``

Draw a filled rectangle centred at the current position with the given radius.

source
``Pen_opacity_random(t::Turtle)``

Change the opacity of the pen to some value at random.

source
``Pendown(t::Turtle)``

Put that pen down and start drawing.

source
``Penup(t::Turtle)``

Pick that pen up and stop drawing.

source
``Pencolor(t::Turtle, r, g, b)``

Set the Red, Green, and Blue colors of the turtle.

source
``Penwidth(t::Turtle, w)``

Set the width of the line drawn.

source

The Point type holds two coordinates. Currently it's immutable, so remember not try to change the values of the x and y values directly.

source
``Pop(t::Turtle)``

Lift the turtle's position and orientation off a stack.

source
``Push(t::Turtle)``

Save the turtle's position and orientation on a stack.

source
``Reposition(t::Turtle, x, y)``

Reposition: pick the turtle up and place it at another position.

source