Prerequisite
How to use
*Create a turtle instance. Give it your commands and call its draw() function in love.draw(), That's it!*
local triangle = Turtle()
function love.load()
-- turtle.lua supports chain methods as you can see below
triangle:forward(60):left(120):forward(60):left(120):forward(60)
end
function love.draw()
triangle:draw()
end
Examples
We added some examples to introduce you turtle library. See what we've done in Examples
As docs.python introduces:
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an import turtle, give it the command turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.right(25), and it rotates in-place 25 degrees clockwise.
By combining together these and similar commands, intricate shapes and pictures can easily be drawn.
Turtle Methods
forward() | fd()
backward() | bk() | back()
right() | rt()
left() | lt()
tl()
rt()
circle()
setheading() | seth()
home()
go_to() | go() | setpos() | setposition()
setx()
sety()
undo(c)
speed()
position()
heading()
xcor()
ycor()
distance()
name()
nodecount()
print()
Drawing state
pendown() | pd() | down()
penup() | pu() | up()
pensize() | width()
isdown()
Color control
color(...)
fillcolor(...)
turtlecolor()
Filling
begin_fill()
end_fill()
Drawing control
reset()
clear()
showturtle() | st()
hideturtle() | ht()
isvisible()
turtlecolor() | tc()
ondrawfinish()
play()
pause()
toggle()
debugon()
debugoff()
drawDebug()
Quick example
local line = Turtle()
local circle = Turtle(100,100,1)
local triangle = Turtle(100,150,1, {1, 1, 1})
function love.load()
local red = {1, 0, 0}
line:clear():right(35):forward(100)
circle:setcolor(1,1,1):penup()
for i=1, 360 do
circle:pendown():right(1):forward(2)
end
triangle:setcolor(red):left(60):forward(50):right(120):forward(50):left(60):backward(50)
end
function love.draw()
line:draw()
circle:draw()
rectangle:draw()
end
Author: Arthurealike
Source Code: https://github.com/arthurealike/turtle.lua
License: MIT license