next up previous contents index
Next: Turtle and 3D Up: List of primitives Previous: List of primitives   Contents   Index

Movement of the turtle; pen and colour settings

This first table sets out the primitives which govern the movement of the turtle.

Primitives Arguments Use
forward, fd n : number of steps Moves the turtle forward n steps in the direction it is currently facing.
back, bk n: number of steps Moves the turtle backwards n steps in the direction it is currently facing.
right, rt n: angle Turns the turtle n degrees towards the right in relation to the direction it is currently facing.
left, lt n: angle Turns the turtle n degrees towards the right in relation to the direction it is currently facing.
circle R: number Draws a circle of R radius around the turtle.
arc R cap1 cap2: numbers Draws an arc of R radius around the turtle. This arc is inscribed between the caps cap1 and cap2.
home any Returns the turtle to its initial position, that is, the co-ordinates [0 0] with a heading of 0 degrees.
setpos, setposition [x y]: list of two nunbers Moves the turtle to the co-ordinates specified by the two numbers in the list (x specifies the x-axis and y the y-axis)
setx x: x-axis Moves the turtle horizontally to the point x on the x-axis
sety y: y-axis Moves the turtle vertically to the point y on the y-axis
setxy x y: x-co-ordinate followed by y-co-ordinate Identical to setpos [x y]
setheading, seth n: heading or bearing Orients the turtle in the specified direction. 0 corresponds to a position facing vertically upwards. The heading when the turtle is rotated is then based on compass bearings.
label a: word or list Draw the specified word or list at the turtle's location, and following the direction it is facing. Eg: label [Hello there!] will write the sentence "Hello there!" wherever the turtle is, and corresponding to its bearing or heading.
labellength a: word or list Returns the length that needs the word or the list to be displayed on the screen with the primitive label using the current font.
dot a: list The point defined by the co-ordinates in the list will be highlighted (in the pen colour).


This second table sets out the primitives which allow the properties of the turtle to be adjusted. For example, should the turtle be visible on screen? What colour should it draw when it moves?
Primitives Arguments Use
showturtle, st none Makes the turtle visible on the screen.
hideturtle, ht none Makes the turtle invisible on the screen.
clearscreen, cs none Empties the drawing area.
wash none Erases the drawing area but leaves the turtle in the same place.
resetall none Initialize the XLogo interface to standard values (PenColor: black, ScreenColor:white, Animation mode: disabled, Text and Graphics Font: Dialog 12 pts, pen shape: square, Drawing quality: normal, turtles allowed: 16, mode trace: disabled, screen size [1000 1000]) and empties the drawing area.
pendown, pd none The turtle will draw a line when it moves.
penup, pu none The turtle will not draw a line when it moves.
penerase, pe none The turtle will rub out any marks that it meets.
penreverse, px none Lower the pen and put the turtle in inverted mode.
penpaint, ppt none Lower the pen and put the turtle in classic drawing mode.
setpencolor, setpc a: whole number or list [r g b] Sets the pen color. See p.[*].
setscreencolor, setsc a: whole number or list [r g b] Sets the screen color. See p.[*].
pos, position none Gives the current position of the turtle.Eg: pos returns [10 -100]
heading none Gives the bearing or heading of the turtle (cf setheading)
towards a: list The list must contain two numbers representing co-ordinates. Gives the heading which the turtle must follow to go towards the point defined by the co-ordinates in the list.
distance a: list The list must contain two numbers representing co-ordinates. Gives the number of steps between the current position and the point defined by the co-ordinates in the list.
pencolor, pc a: list Gives the current colour of the pen. This colour is specified by a list [r g b] where r is the red component, b the blue and g the green.
screencolor, sc a: list Gives the current colour of the screen (background). This colour is specified by a list [r g b] where r is the red component, b the blue and g the green.
window none The turtle can travel outside the drawing area (but of course, it cannot draw there).
wrap none If the turtle leaves the drawing area, it will reappear on the opposite side!
fence none The turtle is confined to the drawing area. If it is about to go outside, an error message will let you know, and give you the maximum number of steps the turtle can move before the exit point is reached (to within 1 or 2 steps ...).
perspective None The turtle can move through 3d Space. (See Special Section [*] for this mode). To quit this mode, Use one of these primitives window, wrap or fence
findcolor,fc a: list Returns to the colour of the a coordinates pixel. This color is determined thanks to a [r g b] list where r is red, g is green and b is blue.
setpenwidth, setpw n: number Defines the thickness of the pen nib in pixels. The default is 1. The pen has a square nib. (Other shapes will be provided in future versions.)
penwidth, pw none Returns the thickness of the pen nib in pixels.
setPenShape, setps 0 or 1 set the pen shape. 0$ \to$square. 1$ \to$oval
penshape, ps none returns the pen shape. 0$ \to$square. 1$ \to$oval
setdq, setDrawingQuality 0 or 1 or 2 set the drawing Quality 0$ \to$normal. 1$ \to$high. 2$ \to$Low
dq, DrawingQuality none returns the drawing Quality 0$ \to$normal. 1$ \to$high. 2$ \to$Low
setscreensize [width height] Set the screen size to the dimension contained in the list. setscreensize [1000 1000]
screensize list Returns the current screen size in a list. setscreensize [1000 1000]
setshape n: number You can choose your preferred turtle with the second tab of menu Options-Preferences.... But you can choose your favourite turtle with setshape. The number n goes from 0 to 6. (0 is the triangular shape).
shape none Returns the number that represents the shape of the turtle.
setfontsize, setfs n: number When you write on the screen with the primitive label, it's possible to modify the size of the font with setfontsize. The size of the font is 12 by default.
fontsize none Returns the size of the font when you write on the screen with the primitive label.
setfn, setfontname n: number Select the font number $ n$ when you write on the screen with the primitive label. You can find the link between number and font in Menu$ \to$OptionsvPreferences$ \to$Tab Font.
fontname none Returns a list with two elements. The first is the number corresponding to the font used when you write on the screen with the primitive label. The last element is a list which contains the name of the font.
setseparation, setsep a: number Determines the ratio between the graphic screen and the history zone. The number a must be included between 0 and 1. When a equals 1 the drawing zone uses all the space, when a equals 0, the history zone uses all the window.
separation, sep none Provides the current ratio between the drawing zone and the history zone.
grid a, b integer Draw a grid. Each square has dimension a and b.
stopgrid none Erase grid.
setgridcolor Color Allow the user to choose a custom color for the grid. Eg: setgridcolor red
gridcolor none Return current grid color.
grid? none Return true if the grid is drawn, else return false.
axis n: integer Draw horizontal and vertical axis. The distance between two divisions is $ n$ steps.
xaxis n: integer Draw only horizontal axis. The distance between two divisions is $ n$ steps.
yaxis n: integer Draw only vertical axis. The distance between two divisions is $ n$ steps.
stopaxis none Erase both axis.
setaxiscolor Color Allow the user to choose a custom color for the axis. Eg: setaxiscolor green
axiscolor none Return current axis color.
xaxis? none Return true if the horizontal axis is drawn, else return false.
yaxis? none Return true if the vertical axis is drawn, else return false.
zoom a Zoom on the drawing screen. In fact, the number a represents the scale regarding to the original image size fixed in the preference panel.
zonesize none Returns a list which contains four numbers. These integers are the coordinates of the left upper corner of the drawing zone and the coordinates for the right bottom corner.
message, msg a: list Shows the message in list in a dialog box, the program stops until the user has clicked the button "OK"


Subsections
next up previous contents index
Next: Turtle and 3D Up: List of primitives Previous: List of primitives   Contents   Index
Loïc 2008-06-08