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

Get top class preparation for competitive exams right from your home: get questions, notes, tests, video lectures and more- for all subjects of your exam.

## Summary of Simple LOGO Commands

 Command Usage Explanation fd fd dist moves the turtle forward in the direction that it is facing, speci ed by dist bk bk dist Same as fd but move backward rt rt angle turns the turtle clockwise by the speci ed angle, measured in degrees lt lt angle same as rt but turns counterclockwise cs cs clears the screen pd pd sets the pen՚s position to DOWN without changing mode (default) pu pu sets the pen՚s position to UP without changing mode penpaint penpaint sets the pen՚s position to DOWN and mode to PAINT (default) penerase penerase sets the pen՚s position to DOWN and mode to ERASE setpc setpc colornumber sets the pen color to the given number (nonnegative inteeger) setsc setsc [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 setfc setfc colornumber sets the fill color (also referred to as food color) to the given number fill fill fills the region enclosing the turtle with the color speci ed by setfc setpos setpos [x y] moves the turtle to an absolute screen position whose coordinates are in the list [x y] setxy setxy xcor ycor same as setpos but the coordinates are supplied as 2 numbers setx setx xcor moves the turtle horizontally from its old position to a new absolute horizontal coordinate, speci ed by xcor sety sety ycor similar to setx but moves vertically home home same as setpos [0 0] ht ht hides the turtle st st shows the turtle pot pot prints out a list of all procedures in the workspace make make ″ x val assigns 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 wait wait k delays execution of the next command for k/60 seconds random random n produces 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.

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

end

### 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]

end

; ; 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.

pu

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

pd

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

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

pu