Summary of Simple Logo Commands, Logo Coordinates, Color Number, Control Structure, Loop Construct, Selection Construct

Get unlimited access to the best preparation resource for AFCAT : get questions, notes, tests, video lectures and more- for all subjects of AFCAT.

Summary of Simple LOGO Commands

Summary of Simple LOGO Commands
fdfd distmoves the turtle forward in the direction that it is facing, speci ed by dist
bkbk distSame as fd but move backward
rtrt angleturns the turtle clockwise by the speci ed angle, measured in degrees
ltlt anglesame as rt but turns counterclockwise
cscsclears the screen
pdpdsets the pen՚s position to DOWN without changing mode (default)
pupusets the pen՚s position to UP without changing mode
penpaintpenpaintsets the pen՚s position to DOWN and mode to PAINT (default)
penerasepenerasesets the pen՚s position to DOWN and mode to ERASE
setpcsetpc colornumbersets the pen color to the given number (nonnegative inteeger)
setscsetsc [r g b]sets the screen background color to the color speci ed by r, g & b which are integers in the range 0 - 255
setfcsetfc colornumbersets the fill color (also referred to as food color) to the given number
fillfillfills the region enclosing the turtle with the color speci ed by setfc
setpossetpos [x y]moves the turtle to an absolute screen position whose coordinates are in the list [x y]
setxysetxy xcor ycorsame as setpos but the coordinates are supplied as 2 numbers
setxsetx xcormoves the turtle horizontally from its old position to a new absolute horizontal coordinate, speci ed by xcor
setysety ycorsimilar to setx but moves vertically
homehomesame as setpos [0 0]
hththides the turtle
ststshows the turtle
potpotprints out a list of all procedures in the workspace
makemake ″ x valassigns value val to variable x. If x does not exist it will be created.

Note the quotes.

To use x we need to put a colon in front of it. For example, fd: x

waitwait kdelays execution of the next command for k/60 seconds
randomrandom nproduces a random number between 0 and inclusively

Logo Coordinates

The center of the graphic window is turtle position [0 0] , i.e.. , the origin. Positive X is to the right, positive Y is up. Headings (angles) are measured in degrees clockwise from the positive Y axis.

Color Number

0. Black

1. Blue

2. Green

3. Cyan

4. Red

5. Magenta

6. Yellow

7. White

8. Brown

9. Tan

10. Forest

11. Aqua

12. Salmon

13. Purple

14. Orange

15. Grey

Control Structure

Function syntax:

; comments starts with a semicolon and is in effect until the end of the line

; this function draws an equilateral triangle

; ; name of function is equilateral. triangle, name can have a period in it.

; ; : edge is a parameter (or argument) of the function

to equilateral. triangle: edge

fd: edge; ; draw first edge

rt 120; ; turn 120 degree to the right, why not 60?

fd: edge; ; draw second edge

rt 120; ; turn 120 degree to the right

fd: edge; ; draw last edge


Loop Construct

repeat times [things to do]

e. g. ,

to square: size|repeat 3 [print (list ″ This ″ is ″ loop repcount) ] ; ; will print

; ; draw a square|This is loop 1

repeat 4 [fd 100 rt 90] | This is loop 2

end|This is loop 3

Selection Construct

if < boolean expression > [things to do]

ifelse < boolean expression M >

[things to do if M is true]

[things to do if M is false]

For example,

make ″ a 1

make ″ b 3

if: a <: b [print list: a: b]

ifelse: a <: b [print list: a: b] [print list: b: a] ; ; output a & b in increasing order

More Examples

; ; This function draws a regular polygon with: n sides and the length

; ; of each side is: length. One vertex of the polygon is the current

; ; position of the turtle.

to ngon: n: length

repeat: n [fd: length rt 360 /: n]


; ; This function draws a regular polygon with: n sides and radius: rad

; ; The polygon is centered at the current position of the turtle

; ; This function uses the function ngon given above.

to cngon: n: rad


fd: rad

rt 180 - (90 ⚹ (: n - 2) /: n)


ngon: n (2 ⚹: rad ⚹ sin (180 /: n) )

lt 180 - (90 ⚹ (: n - 2) /: n)


bk: rad



Developed by: