Using commands you tell the turtle or KTurtle to do something. Some commands need input, some give output. In this section we explain all the built-in commands of KTurtle. Alternatively, using learn, you can create your own commands. Built-in commands we discuss here are highlighted with dark blue.
There are several commands to move the turtle over the screen.
- gox
gox X
goxusing this command the turtle will move to X pixels from the left of the canvas whilst staying at the same height.goxcan be abbreviated togx.
- goy
goy Y
goyusing this command the turtle will move to Y pixels from the top of the canvas whilst staying at the same distance from the left border of the canvas.goycan be abbreviated togy.
Note
Using the commands go, gox, goy and center the turtle will not draw a line, no matter if the pen is up or down.
The turtle has a pen that draws a line when the turtle moves. There are a few commands to control the pen. In this section we explain these commands.
- penwidth (pw)
penwidth X
penwidthsets the width of the pen (the line width) to an amount of X pixels.penwidthcan be abbreviated topw.
- pencolor (pc)
pencolor R,G,B
pencolorsets the color of the pen.pencolortakes an RGB combination as input.pencolorcan be abbreviated topc.
There are several commands to control the canvas.
- canvascolor (cc)
canvascolor R,G,B
canvascolorset the color of the canvas.canvascolortakes an RGB combination as input.canvascolorcan be abbreviated tocc.
There are two commands to clean up the canvas after you have made a mess.
- reset
reset
resetcleans much more thoroughly than theclearcommand. After aresetcommand everything is like is was when you had just started KTurtle. The turtle is positioned at the middle of the screen, the canvas color is white, the turtle draws a black line on the canvas and the canvassize is set to 400 x 400 pixels.
First a brief explanation of what sprites are: sprites are small pictures that can be moved around the screen, like we often see in computer games. Our turtle is also a sprite. For more info see the glossary on sprites.
Next you will find a full overview on all commands to work with sprites.
[The current version of KTurtle does not yet support the use of sprites other than the turtle. With future versions you will be able to change the turtle into something of your own design]
The answer is: “yes”. The turtle can write: it writes just about everything you command it to.
print X
The
printcommand is used to command the turtle to write something on the canvas.printtakes numbers and strings as input. You canprintvarious numbers and strings using the “+” symbol. See here a small example:$year = 2003 $author = "Cies" print $author + " started the KTurtle project in " + $year + " and still enjoys working on it!"
- fontsize
fontsize X
fontsizesets the size of the font that is used byprint.fontsizetakes one input which should be a number. The size is set in pixels.
The following commands are KTurtle's more advanced mathematical commands.
- random (rnd)
random X,Y
randomis a command that takes input and gives output. As input are required two numbers, the first (X) sets the minimum output, the second (Y) sets the maximum. The output is a randomly chosen number that is equal or greater than the minimum and equal or smaller than the maximum. Here a small example:repeat 500 { $x = random 1,20 forward $x turnleft 10 - $x }Using the
randomcommand you can add a bit of chaos to your program.
- sin, cos, tan
sin X cos X tan X
These three commands represent the world famous trigoniometrical functions
sin,cosandtan. The input argument of these commands, X, is a number.
A dialog is a small pop-up window that provides some feedback or asks for some input. KTurtle has two commands for dialogs, namely: message and ask
- ask
ask X
asktakes a string as input. It shows this string in a pop-up dialog (similar to message), along with an input field. After the user has entered a number or a string into this, the result can be stored in a variable or passed as an argument to a command. For example:$in = ask "What is your year of birth?" $out = 2003 - $in print "In 2003 you were " + $out + " years old at some point."
If the user cancels the input dialog, or does not enter anything at all, the variable is empty.