LOGO Basics

On this page, we will explore the basic LOGO commands that enable us to draw various shapes. LOGO supports turtle move commands, loop commands (REPEAT and REPCOUNT), and several pen control and color control commands.

Let’s learn them one at a time on this page and the following few pages.

The LOGO Start-up Screen

After you have downloaded FMSLOGO, double click the FMSLOGO icon.  This will result in the following screen on the computer screen.

LOGO Start-up Screen
LOGO START-UP SCREEN

Note that on the LOGO start-up screen above, there is a triangle, which represents the turtle. When you start LOGO, the turtle starts at coordinates (0,0), which is also called the HOME position of the turtle.  At start-up, the turtle faces up (North). The rectangular start-up screen is the playground of the turtle.  When you instruct the turtle to move, it moves around in its playground. Note that since at LOGO start-up, the turtle is facing up, this is the direction the turtle will move if you give the command to move forward.

The thing to note is that the turtle is pointing in a particular direction and can only move in that direction. It can move forward or back, like a car with reverse gear, but not sideways. In order for the turtle to move in any other direction, the turtle must first turn (similar to a car) so that it is facing in the new direction.

LOGO Basic Commands

LOGO has four basic commands:

Forward (or abbreviation FD): FD 100 command moves the turtle forward 100 spaces (pixels) in the direction it is facing.

Back (or abbreviation BK): BK 100 command moves the turtle 100 spaces back in the direction of its tail.

Right (RT): RT 90 command turns the turtle 90 degrees to the right.

Left (LT): LT 90 command turns the turtle 90 degrees to the left.

Note: In the instruction ‘FD 100’, the number 100 is the distance (number of pixels) that you would like the turtle to move.  You can change ‘100’ to any number that you want the turtle to move by.

Similarly, in the instruction ‘RT 90’, the number 90 is the angle that you want the turtle to turn by. Use any angle that you want the turtle to turn by.

Moving the Turtle in its Playground

With the turtle at its Home position (0,0), let us give the following commands as in the short program below to move the turtle forward 100 pixels by typing FORWARD 100 in the command line (see start-up screen picture above). Since the turtle is facing up, it moves up by 100 pixels. The next command (RIGHT 90) tells the turtle to turn its face towards the right by 90 degrees. The last command FORWARD 100 moves the turtle 100 pixels in the direction it is facing. The concept of pixels is discussed here.

PROGRAM EXAMPLE: MOVE THE TURTLE UP AND THEN RIGHT
FORWARD 100; The turtle moves 100 pixels in the direction it is facing.
RIGHT 90; The turtle turns it face to the right by 90 degrees.
FORWARD 100; The turtle moves forward 100 pixels in the direction it is facing.

The figure below shows the turtle move up 100 pixels shown by the red up arrow as a result of the first command (FORWARD 100). The coordinates of the turtle at this location is (100,0). The second command (RIGHT 90) makes the turtle’s face turn right by 90 degrees (shown by the red triangle). Finally, the third command (FORWARD 100) moves the turtle 100 pixels in the direction it is facing (right). This is shown by the red arrow going in the right direction. The final location of the turtle is shown by the blue triangle.  The turtle’s new location coordinates are (100,100).

LOGO Move the Turtle to Coordinates (100,100) in the First Quadrant.
FD 100 FOLLOWED BY COMMANDS RT 90, FD 100 MOVES THE TURTLE TO THE FIRST QUADRANT

Let us move the turtle in a different direction to help you understand the coordinate system. This time, we give the following instructions to the turtle starting from the HOME position (0,0). As mentioned above, the turtle faces up at the LOGO start-up. The BACK 100 command will move it back (that is down) by 100 pixels shown by the red arrow pointing downwards. The next two commands RIGHT 90 and FORWARD 100 do the same thing as in the previous example.

PROGRAM EXAMPLE: MOVE THE TURTLE BACK AND RIGHT TO THE THIRD QUADRANT
Back 100; Move the turtle down by 100 pixels
Right 90
Forward 100

The final position of the turtle is shown by the blue triangle.  The coordinates of the final turtle location is [-100, -100], which is in quadrant-3.

LOGO Move the Turtle to the Third Quadrant
COMMAND BK 100, RT 90, FD 100 MOVES THE TURTLE TO COORDINATES (-100,-100) IN THE THIRD QUADRANT

Adding Comments To Your Code

It is a good practice to add comments to your code.  This helps the reader of your program to understand what you are doing and what your thinking is.  The comments start with the symbol (;) semicolon.  All statements following a semicolon (;) are ignored by the computer. These are called comments and are written to make the program more readable and understandable by the reader.

Teach the Turtle How to Draw Polygons

Square

To make the turtle draw a square, we type the following commands numbered 1), 2), 3), and 4) in the description below.  Since the square has four sides and each corner of the square has 90 degrees angle, you will write the following four commands. Note that the turtle has a pen its belly. As it moves, it draws a trace on its playground.

1)  FORWARD 300 RIGHT 90: The turtle will move forward 300 spaces and then turn right by 90 degrees.

2) FORWARD 300 RIGHT 90: The turtle will again move forward 300 spaces and turn right by 90 degrees.

3) FORWARD 300 RIGHT 90: The turtle will again move forward 300 spaces and turn right 90 degrees.

4) FORWARD 300 RIGHT 90: The turtle will move forward 300 spaces and turn right 90 degrees.

The above four commands will make the turtle draw a square shown below.

LOGO Draw a Square Using LOGO FORWARD and RIGHT Commands
DRAW A SQUARE OF SIDES 300 PIXELS USING FD 300 RT 90 COMMANDS FOUR TIMES

Pentagon

The pentagon has five sides and has an exterior angle of 72 degrees.  So you will give the instruction FORWARD 300 RIGHT 72 five times as in the program below.

PROGRAM EXAMPLE: MAKE THE TURTLE DRAW A PENTAGON
FORWARD 300 RIGHT 72
FORWARD 300 RIGHT 72
FORWARD 300 RIGHT 72
FORWARD 300 RIGHT 72

The turtle will move forward 300 spaces and turn right 72 degrees for each of the five times we give this command and will complete the pentagon shape.

LOGO Draw a Pentagon With Sides = 300 Pixels
DRAW A PENTAGON OF SIDES = 300 PIXELS USING FD 300 RT 72 COMMANDS FIVE TIMES

Hexagon

What if you would like to draw a hexagon? Well, we refer to the table in the Basic Geometry Concepts chapter and we will find that the hexagon has six sides and its exterior angle is 60 degrees. So, we will type FD 300 RT 60 six times as in the program below.

Note we are going to use the abbreviation FD for FORWARD and RT for RIGHT in this program.

PROGRAM EXAMPLE: MAKE THE TURTLE DRAW A HEXAGON
FD 300 RT 60
FD 300 RT 60
FD 300 RT 60
FD 300 RT 60
FD 300 RT 60
FD 300 RT 60

The above code will draw a hexagon with each side = 300 pixels. Try it on your computer and see if the turtle draws a hexagon on your screen.

Octagon

If we refer to the Table in the Basic Geometry Concepts chapter, we see that the octagon has 8 sides and the exterior angle is 45 degrees. So, we will type FD 300 RT 45 eight times. The following code will draw an octagon with each side = 300 pixels.

PROGRAM EXAMPLE: MAKE THE TURTLE DRAW A HEXAGON
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45
FD 300 RT 45

Enter this program on the command line on the LOGO start-up screen and watch the turtle draw an octagon for you on the computer screen.

Notice that in all the examples above to draw polygons, the program repeats the same command several times. There is an easier way to do it by using the REPEAT command discussed on “Loops in LOGO” page.

Draw a Circle

The CIRCLE radius command draws a circle based on the turtle’s position and the radius input. The center point of the circle is the turtle’s current position. The CIRCLE command does not move the turtle. In the program example below, the CIRCLE 50 command draws a circle of radius 50.  The center of the circle is the turtle’s current position.

“CIRCLE” is discussed in detail on the Math Applications page.

PROGRAM EXAMPLE: DRAW CIRCLE
PENUP; 
SETXY -250 100 ; Set turtle position to (-250, 100).
HIDETURTLE; Hide the turtle so that the turtle does not show on the circle image.
SETPENSIZE 3; Set pen size to 3 so that the turtle draws thicker circle outline.
SETPENCOLOR 4; Draw circle outline in RED color.
PENDOWN; Enable the turtle to draw as it moves.
Circle 50; Draw a circle of radius = 50.

PENUP command moves the turtle’s pen up so that it does not draw a trace when it moves to coordinates (-250,100).

SETPENSIZE 3 command sets the pen’s thickness.

SETPENCOLOR 4 selects the turtle’s pen color.

PENUP, SETPENSIZE, and SETPENCOLOR commands will be discussed in the chapter LOGO PEN CONTROL and COLOR CONTROL The following is the program’s output.

LOGO CIRCLE Command
DRAW A CIRCLE OF RADIUS = 50 PIXELS

Note: For LOGO Additional commands refer to the pages “LOGO Additional Commands“, “LOGO Output Commands“, “LOGO Arithmetic Commands“, and “LOGO Control Commands“.

You can draw interesting shapes using FORWARD and TURN statements as in the link below.

<a href=”https://en.wikipedia.org/wiki/Turtle_graphics“>

Saving Your Program

Once you have written a program, you should save it to a file on the computer disk so you can use it again. The edits you’ve made so far are all in Logo’s memory and not on the disk. The commands to save your program on your disk are below.

SAVE “ProgramName.LGO

BYE

When you would like to use your saved program again, you’ll need to load them. The following is how you load your saved program from the disk to the computer’s memory.

LOAD “ProgramName.LGO

Copyright © 2019 – 2023 softwareprogramming4kids.com

All Rights Reserved

Verified by MonsterInsights