![]() | KTurtle's Logo Programming Reference |
Prev | Next |
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 commands that can be used in KTurtle.
There are several commands to move the turtle over the screen.
forward Xforward moves the turtle forward by the amount of X pixels. When the pen is down the turtle will leave a trail. forward can be abbreviated to fw
backward Xbackward moves the turtle backward by the amount of X pixels. When the pen is down the turtle will leave a trail. backward can be abbreviated to bw.
turnleft Xturnleft commands the turtle to turn an amount of X degrees to the left. turnleft can be abbreviated to tl.
turnright Xturnrightthe turtle to turn an amount of X degrees to the right. turnright can be abbreviated to tr.
direction Xdirection set the turtle's direction to an amount of X degrees counting from zero, and thus is not relative to the turtle's previous direction. direction can be abbreviated to dir.
centercenter moves the turtle to the center on the canvas.
gox Xgox using this command the turtle will move to X pixels from the left of the canvas while she keeps his height.
goy Ygox using this command the turtle will move to Y pixels from the top of the canvas while she keeps his on the same distance from the left border of the canvas.
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.
penuppenup lifts the pen from the canvas. When the pen is “up” no line will be drawn when the turtle moves.See also pendown.penup can be abbreviated to pu.
pendownpendown presses the pen down on the canvas. When the pen is press “down” on the canvas a line will be drawn when the turtle moves. See also penup.pendown can be abbreviated to pd.
penwidth Xpenwidth sets the width of the pen (the ligne width) to an amount of X pixels.penwidth can be abbreviated to pw.
pencolor R,G,Bpencolor sets the color of the pen. pencolor takes an RGB combination as input.pencolor can be abbreviated to pc.
There are several commands to control the canvas.
canvascolor R,G,Bcanvascolor set the color of the canvas. canvascolor takes an RGB combination as input.canvascolor can be abbreviated to cc.
There are two commands to clean up the canvas after you have made a mess.
clearWith clear you can clean all drawings from the canvas. All other things remain: the position and angle of the turtle, the canvascolor, the visibility of the turtle and the canvas size.clear can be abbreviated to ccl.
resetreset cleans much more thoroughly than the clear command. After a reset command everything is like is was when you had just started KTurtle. The tortle is positionned at the middle of the screen, the canvas color is white and the turtle daws a black line on the canvas.
Many people do not know what sprites are, so here a short explanation: sprites are small pictures that can be moved around the screen. (for more info see the glossary on sprites). So the turtle is a sprite!
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!]
showshow makes the turtle visible again after she has been hidden.show can be abbreviated to ss.
hidehide hides the turtle. This can be used if the turtle does not fit in your drawing.hide can be abbreviated to sh.
The answer is: “yes”. The turtle can write, he writes just about everything you command him to.
print XThe print command is used to command the turtle to write something on the canvas. print takes numbers and strings as input. You can print various numbers and strings using the “+” symbol. See here a small example:
year = 2004 author = "Cies" print "KTurtle was made in " + year + " by " + author
fontsize Xfontsize sets the size of the font that is used by print. fontsize takes one input which should be a number. The size is set in pixels.
There is one command that rolls a dice for you
random X,Yrandom is 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 then 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 random command you can add a bit of chaos to your program.
Prev | Home | Next |
Getting Started | Up | Containers |