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()
Luxor.Turtle
— Type.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.
Luxor.Forward
— Function.Forward(t::Turtle, d)
Move the turtle forward by d
units. The stored position is updated.
Luxor.Turn
— Function.Turn(t::Turtle, r)
Increase the turtle's rotation by r
degrees. See also Orientation
.
Luxor.Circle
— Function.Circle(t::Turtle, radius)
Draw a filled circle centered at the current position with the given radius.
Luxor.HueShift
— Function.HueShift(t::Turtle, inc = 1)
Shift the Hue of the turtle's pen forward by inc
.
Luxor.Message
— Function.Message(t::Turtle, txt)
Write some text at the current position.
Luxor.Orientation
— Function.Orientation(t::Turtle, r)
Set the turtle's orientation to r
degrees. See also Turn
.
Luxor.Randomize_saturation
— Function.Randomize_saturation(t::Turtle)
Randomize saturation of the turtle's pen color.
Luxor.Rectangle
— Function.Rectangle(t::Turtle, width, height)
Draw a filled rectangle centered at the current position with the given radius.
Luxor.Pen_opacity_random
— Function.Pen_opacity_random(t::Turtle)
Change the opacity of the pen to some value at random.
Luxor.Pendown
— Function.Pendown(t::Turtle)
Put that pen down and start drawing.
Luxor.Penup
— Function.Penup(t::Turtle)
Pick that pen up and stop drawing.
Luxor.Pencolor
— Function.Pencolor(t::Turtle, r, g, b)
Set the Red, Green, and Blue colors of the turtle.
Luxor.Penwidth
— Function.Penwidth(t::Turtle, w)
Set the width of the line drawn.
Luxor.Point
— Type.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.
Luxor.Pop
— Function.Pop(t::Turtle)
Lift the turtle's position and orientation off a stack.
Luxor.Push
— Function.Push(t::Turtle)
Save the turtle's position and orientation on a stack.
Luxor.Reposition
— Function.Reposition(t::Turtle, x, y)
Reposition: pick the turtle up and place it at another position.