logo - holistic healing  · web viewwe speak and hear many languages such as hindi, english,...

51
LOGO We speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer languages, such as LOGO, BASIC, PASCAL, COBOL, C, etc. Since the computer does not understand our language, hence to work on a computer, we must learn a computer language. A language is a way of talking, writing or reading. Similarly, we will talk to our computer in LOGO language. A computer language is one, which a computer can understand. LOGO is one of the computer languages. LOGO is the easiest and simplest computer language. You can draw, do sums, write and can do any kind of work with it. When we want to work in LOGO language, we have to provide he LOGO program to the computer. Just as when you want to hear the songs of a particular movie, you have to put the audiocassette of that movie in the tape-recorder and then switch on the tape. Similarly, LOGO language is available on a floppy disk. We must put the floppy in the computer drive and type LOGO. Let’s see the stepwise procedure to put LOGO on the computer. Switch on all the connections of the computer. Switch on the CPU button. Switch on the monitor. Wait for few seconds. Now your screen will look like this. Now type CD Logo and press ENTER key. Now type Logo again and press ENTER key. Once LOGO is stored properly in the CPU, it will display the LOGO screen. TURTLE: When we work with LOGO on the computer, a triangle is seen in the center of the screen. This triangle is known as TURTLE. Beneath the TURTLE on the left side of the screen a question mark and small, thick bar appears that is known as cursor. Here we type our orders and Turtle who is our friend obeys our orders. Let’s meet our friend, the TURTLE. The center of the screen is the Turtle’s home.

Upload: others

Post on 09-Jan-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

LOGO

We speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer languages, such as LOGO, BASIC, PASCAL, COBOL, C, etc. Since the computer does not understand our language, hence to work on a computer, we must learn a computer language. A language is a way of talking, writing or reading. Similarly, we will talk to our computer in LOGO language. A computer language is one, which a computer can understand.

LOGO is one of the computer languages. LOGO is the easiest and simplest computer language. You can draw, do sums, write and can do any kind of work with it. When we want to work in LOGO language, we have to provide he LOGO program to the computer.

Just as when you want to hear the songs of a particular movie, you have to put the audiocassette of that movie in the tape-recorder and then switch on the tape. Similarly, LOGO language is available on a floppy disk. We must put the floppy in the computer drive and type LOGO. Let’s see the stepwise procedure to put LOGO on the computer.Switch on all the connections of the computer.Switch on the CPU button.Switch on the monitor. Wait for few seconds. Now your screen will look like this.Now type CD Logo and press ENTER key.Now type Logo again and press ENTER key.Once LOGO is stored properly in the CPU, it will display the LOGO screen.

TURTLE:

When we work with LOGO on the computer, a triangle is seen in the center of the screen. This triangle is known as TURTLE. Beneath the TURTLE on the left side of the screen a question mark and small, thick bar appears that is known as cursor. Here we type our orders and Turtle who is our friend obeys our orders.

Let’s meet our friend, the TURTLE. The center of the screen is the Turtle’s home.

Our friend TURTLE moves all over the screen on our order. Whenever TURTLE moves on the screen, it leaves a trail.

Turtle’s body has two parts. The top point, which is facing the upper side of the screen, is called NOSE and the other part i.e., the bottom part is called TAIL or BACK. If TURTLE has moved anywhere on the screen, and you want it to go back to the center of the screen, i.e., it’s home, then type HOME and press ENTER. The TURLTLE follows your order and returns to its home, the center of the screen.

PROGRAM AND PRIMITIVE

Mary is a girl of your age studying in the third standard. Mary’s mother has prepared a program for her after school. It is as follows:Mary will go home, remove her shoes and uniform.Then she will have a wash.Then she will have some snacks and go to play.After playing, she will do her homework.

Page 2: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

So here are some instructions set by Mary’s mummy for her. A set of instructions to do a work is called program.

The TURTLE is our most obedient friend. The TURTLE will obey all our orders and will do whatever we want. But all this is possible when only if it understands our orders. So we have to communicate with the TURTLE in a language, which it can understand. Our friend TURTLE has a special name for our orders. TURTLE calls our orders by the name PRIMITIVES. Orders given to the TURTLE are called PRIMITIVES.

These primitives or orders given to the TURTLE to do a particular work are called a program. Thus, a set of primitives given to the TURTLE to do a particular work is called a program.

Let’s try this primitive on our friend!

Type FD 50 and then press ENTER key.

What happens?

Yes! The TURTLE has moved up. You are surely picking up the Logo language well.

Can you recall how you had got the TURTLE in the center of the screen, the first time? Remember you had given one order, …sorry primitive ‘HOME’, right? So now at question mark type HOME and press ENTER key.

HOME (press enter key)

Wow! TURTLE has moved back to the center of the screen and it has left a trail behind it.

You brought the TURTLE back with two primitives --- so you call it a program. Hence a program means many orders, many primitives!

LOGO SCREEN AND RULES FOR WRITING PRIMITIVES

When the screen has a question mark and a cursor, it means LOGO is ready to take our instructions, and we can give primitives to the TURTLE to do the work. Turtle is very fussy. It demands proper numbering and correct spelling of the primitives.

If you make a mistake and enter your program, TURTLE will not obey your orders, and Turtle’s answer, “This is not a Logo procedure” will appear on the screen.

So remember, we have to follow certain rules when we write primitives. As we have rules for English grammar, Marathi grammar, etc., similarly, we have rules for the grammar of computer languages too.

Grammar used for any computer language is called SYNTAX.

If we do not follow the syntax rules, then LOGO Turtle points out our mistakes and says, “I do not know”.

RULES FOR WRITING PRIMITIVES:

Page 3: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

We must write the correct spelling of the primitive.We must leave a gap between primitives and numbers.Once we write the primitive and number then we must press the ENTER key. As soon as we press the ENTER key, TURTLE executes the order which has been given to it.

HOW TO COME OUT OF LOGO?

After you finish working with LOGO, at question mark type .DOS and press Enter key. It will show you the original screen.

RECAP

LOGO is a computer language.Computer language is a language, which the computer can understand.In LOGO, there is a moving triangle, which is known as TURTLE.TURTLE’S body has two parts, Nose and Back.TURTLE’S home is in the center of the screen.A set of instructions to do a particular work is known as program.Order given to the TURTLE is known as primitive.‘HOME’ primitive brings back the TURTLE to the center of the screen and when the TURTLE returns home, it leaves a TRAIL behind it.

Learn the words:

The full form of LOGO is Logic Oriented Graphic Oriented.LanguageOrientedGraphicsPrimitivesProgramTurtle.

LOGO PRIMITIVES

The instructions or to say orders which we give the turtle as known as primitives in LOGO language. They are also known as commands. In fact, all preliminary orders or commands of LOGO are known as primitives. Examples of primitives are:FORWARD, BACK, CLEAN, DRAW, CS, REPEAT, RIGHT, LEFT, and HOME etc.

Let us quickly recall the commands that you know in LOGO.

RIGHT OR RT COMMAND

The RIGHT command will rotate the turtlehead in the clockwise followed by an input.Example: RIGHT 45 or RT 45

RT 45 will rotate the turtlehead in the clockwise direction by 45 units from the current position.

LEFT OR LT COMMAND

Page 4: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The LEFT command will rotate the turtlehead in the anticlockwise direction for the given number of units. This command is also followed by an input. Example: LEFT 45 or LT 45

LT 45 will rotate the turtlehead in the anticlockwise direction by 45 units from the current position.

SETH COMMAND

The SETH command followed by a number will set the turtle head in a specific direction. The turtle head is not rotated for the given units as in the case of RIGHT or LEFT commands, rather it is fixed in the given direction. The directions are indicated as 0. At the top, 90. Towards right, 180. at the bottom, 270. Towards left and 360. Again towards the top.Example: SETH 45

HOME COMMAND

The Home command will set the turtlehead to its default position. The home position of the turtle is the center of the screen.

FORWARD OR FD COMMAND

This command is used to draw a line in the forward direction. A number follows it.The number indicates the length of the line the turtle has to draw.

BACK OR BK COMMAND

This is used to draw a line in the backward or reverse direction. A number also follows it.

PENUP AND PENDOWN COMMANDS

These commands are used to decide whether the turtle has to draw a line or not.

In MSW Logo, the turtle’s pen, if it is down, can operate in three modes; PAINT, REVERSE, and ERASE.

PENPAINT OR PPT COMMAND

This command sets the turtle’s pen position to DOWN and the mode to PAINT. PAINT is the normal mode for the turtle to draw. Thus when the turtle’s mode is in the PAINT position it draws along its path.Example: FORWARD 20 RIGHT 90 FORWARD 20 LEFT 90 PENERASE FORWARD 20 RIGHT 45 PENPAINT

Page 5: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

FORWARD 20In the above, PENPAINT is given to restore the turtle to the drawing mode.PENERASE OR PE COMMAND

This command sets the turtle’s pen position to down and the mode to erase. Any drawing commands followed after the PENERASE command will erase all the lines, on its way.

PENREVERSE OR PX COMMAND

This command sets the turtle’s pen position down and the mode to reverse. The reverse mode on its way will change the status of the point. That is, on the way, if there are lines already, this command will erase it. On the other hand if there is no line, then it will draw the line.

So the PAINT mode always draws a line, whereas the reverse mode will change the effect, i.e., drawing a line or erasing it depending on the status of the path.

HIDETURTLE AND SHOWTURTLE COMMANDS

We have also discussed how to hide and display the turtle. The HT command will hide the turtle and the ST command will show the turtle.

TEXT COMMANDS

Text screen Command helps to print the text information. If any other command related to the text is given after this command, it will switch from the drawing mode to the text mode.

Print Command is used to print any text or number on the LOGO screen.

To print any number, give the PRINT command followed by that number. For example, PRINT 120

To print any text, give the PRINT command followed by the text, either in quotation marks, or inside square brackets.For example, PRINT, “I AM WORKING WITH LOGO” PRINT, [I AM WORKING WITH LOGO]

SHOW COMMAND

This command is available in MSW Logo. SHOW will display the input values on the screen. This command is of the following form:SHOW value1, value2…Where, Value1, value2… are the things you wish to display on the screen.This command is used to print the input. Its action is similar to PRINT, except than if an input is a list, it is printed inside square bracket.

REPEAT COMMAND

Sometimes, you may have to repeat a command more than once to draw an object. For example, to draw a square, you have to give the following command four times. FD 40 RT 90

Page 6: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

In a square, all the four sides are of equal length. After drawing each side, you have to turn the turtlehead by 90 units and then give the FORWARD command.

FD 40RT 90FD 40RT 90FD 40 RT 90FD 40RT 90The FD 40 and RT 90 commands are repeated four times to draw this square. The same effect can be achieved using the REPEAT command.REPEAT 4 [FD 40 RT 90]

The number 4 indicates that the command must be repeated four times. The commands are enclosed inside square brackets. Try to draw a square using the above command.The REPEAT command is very useful for drawing different shapes.Now, let us draw a rectangle.

What is the difference between a square and a rectangle? In a square, all the four sides are of equal length whereas in a rectangle only the opposites sides are equal.

Try the following commands and see whether you get a rectangle.

HOMECLEARSCREENREPEAT 2 [FD 30 RT 90 FD 50 RT 90]The HOME command will bring the turtle to its original position.The CLEARSCREEN command will erase all the existing pictures.The number 2 follows the REPEAT command. This indicates that the commands given within brackets will be repeated twice.FD 30 will draw a line of 30 units in the forward direction (which is the breadth).RT 90 will turn the turtlehead by 90 units in the clockwise direction.FD 50 will draw a line of 50 units (which is the length).RT 90 will turn the turtlehead by 90 units in the clockwise direction.The FD 30 RT 90 FD 50 RT 90 command will draw one breadth and one length of a rectangle.If this is repeated again, you will get the whole rectangle.

Now try the following commands and find what shape you get on the screen.CLEARSCREENFD 50RT 120FD 50RT 120FD 50RT 120

Have you got a triangle? How many sides does a triangle have? It has 3 sides. Hence the FD 50 and RT 120 commands are given 3 times.

Page 7: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Try to draw the same triangle using the REPEAT command.CLEARSCREENREPEAT 3 [FD 50 RT 120]

Can you understand the significance of RT 120?You would have learnt in your mathematics class that any closed object has a total angle of 360. If you divide it by the number of sides of the object, you get the angle for each side.

A square has 4 sides and each side will have and angle of 360/4 = 90.A triangle has 3 sides and each side will have an angle of 360/3 = 120.

Hence you need the RT 120 command for drawing the triangle.

REPEAT INSIDE REPEAT COMMAND

If you want to draw two triangles in different positions, say from 0. And 90, what commands will you use?

CLEARSCREEN REPEAT 3 [FD 50 RT 120]RT 90REPEAT 3 [FD 50 RT 120]

Here the REPEAT 3 [FD 50 RT 120] command is given two times. The same effect can be obtained using the commands in a different way.CLEARSCREENREPEAT 2 [REPEAT 3 [FD 50 RT 120] RT 90]

Do you understand how the REPEAT command is used another REPEAT command? Try the above command by changing the first REPEAT to 4 in place of 2.

What shape will you get?

SETSCRUNCH command

By this command, you may change the height of a picture to be drawn next by changing the height of the turtle. SETSCRUNCH 1 restores turtle height to normal. SETSCRUNCH 2 doubles the height of a picture while SETSCRUNCH .5 will reduce the height of a picture to half. By the commands below, you may draw a flattened Square of half the normal height,? CS? SETSCRUNCH .5? REPEAT 4 [FD 50 RT 90]? HT

By the SETSCRUNCH .5 command, the height of the turtle is changed to half its normal. Now, whatever way you move the turtle, it will only move half the normal distance vertically. Thus, the resulting drawing will be a half-height picture. Remember, the horizontal width of the picture does not change with SETSCRUNCH command; only its vertical height is changed. If the SETSCRUNCH parameter value is less than 1, the height is reduced, and if it is more than 1, the height is increased.

Page 8: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Even FD and RT can easily draw this short height picture. But, flattened circle or ellipse cannot be drawn easily in any other way. You may draw this picture very easily by using the SETSCRUNCH command as shown in the figure below. Notice the use of the second SETSCRUNCH 1 for making the height of further drawings normal. SETSCRUNCH .2 reduces the height of a picture to one-fifth of the normal height. Remember, till you make the height of the turtle normal by SETSCRUNCH 1, all the pictures drawn will continue to be of changed height only.

? CS ST? REPEAT 360 [FD 1 RT 1]? SETSCRUNCH .2? REPEAT 360 [FD 1 RT 1]

SPLITSCREEN, TEXTSCREEN AND FULLSCREEN

The LOGO screen in which you draw pictures by commands has two portions. The picture is drawn in the upper portion and commands are given in the lower. The upper portion has 20 lines and the lower has 5 lines of vertical space. But when LOGO starts running, the full screen of 25 lines of vertical space is reserved for giving commands only. You cannot draw any picture in it. Recall that you had given DRAW command for starting drawing. This divided the screen into two portions and you started to draw pictures in the upper portion by giving commands in the lower one. Instead of DRAW command, you could also have also pressed F2 key or given SPLITSCREEN (SS in short) command for doing the same job. The drawing portion of the screen is 160 turtle steps high and 320 turtle steps wide.

TEXTSCREEN (TS ion short) command transforms the full area of the screen for typing commands only. Normally, your screen has only five command lines at the bottom. But, when the screen is transformed into a text screen, all the 25 lines become reserved for typing commands. No space remains for drawing. Though you cannot see pictures in this condition, any picture that you were drawing before giving this command still remains in RAM. You can bring it and also the drawing screen back by the command SPLITSCREEN (SS in short).

Just as you convert the screen to text screen by TS, the complete screen can also be converted to be used only for drawing. You may do this by the command FULLSCREEN (FS in short) or by pressing the F4 key. There will be no space on the screen for your commands. You may still give commands in this condition, but these won’t be displayed on the screen. This full drawing screen is 200 turtle steps high and 320 turtle steps wide.

WINDOW, FENCE AND WRAP

When you draw, you give the commands in the lower portion and the picture is drawn in the upper. The upper part is 160 turtle steps high and 320 steps wide. This is the drawing area of the screen. The turtle starts to draw from its home at the center of the screen. That means, it can move 80 steps upward and 80 steps downward before meeting the boundaries of the drawing area of the screen.

If you give the command FD 120, the turtle would move 80 steps upward reaching the screen boundary. It will not stop there. It will wrap around and start from the bottom of the drawing area of the screen to cover the rest of the journey. That will be 40 steps more.

Page 9: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

This is shown in the next figure. This is called wrapping. Under normal circumstances, if the drawing gets larger than the screen, it wraps around the opposite sides. If you want to stop this, FENCE command is to be used. After giving this command, if you now give the command FD 120, LOGO would display,TURTLE OUT OF BOUNDS

WRAP command restores this wrapping property again. To draw outside the screen, WINDOW command is sometimes used. After you give this command, turtle continues drawing even if it goes out of the screen. In this case, you won’t be able to see the drawing.

The area bounded by the dotted line and upper edge of the screen vertically, and left and right edges of the screen horizontally are the drawing area of the turtle. This area is 160 turtle steps high and 320 turtle steps wide. Usually, the turtle can move around and draw pictures only in this area. Similarly, the area below the dotted line is the command area. You can see a maximum of five commands in this area and in the bottom-most of these is your command line.

With FULLSCREEN command, this drawing area covers the full screen and its height increases to 200 turtle steps. The commands given are stored in RAM and are not shown on the screen.

Points to remember

The RT, LT, SETH and HOME commands are used to rotate the head of the turtle in a given unit direction.The FD and BACK commands are used to draw lines.The PENUP command is used to move the turtle without making lines. This action can be reversed by a PENDOWN command. The PENERASE command is used to erase the drawings.The TEXTSCREEN command will switch between the text screen and the drawing screen. The PRINT command prints any text or number on the screen.The CLEARSCREEN command will erase all the pictures and command from the screen and place the turtle at its original position.The REPEAT command is used to repeat any command more than once.The REPEAT command is followed by a number (indicating the number of times the command is to be repeated) and the set of commands to be repeated (inside square brackets).The RPEAT inside REPEAT command is used to draw the same picture from different positions any number of times.In MSW Logo Pen can be to three different modes, PAINT, ERASE or REVERSE.PENPAINT (PPT) command will enable the turtle to draw lines.PENERASE (PE) command will enable the turtle to erase the drawings.PENREVERSE (PX) command will either erase or draw the lines based on whether the drawing exists on the path or not.SHOW command will print the input values (number, text or list). List items are printed inside a set of square brackets, unlike the PRINT command.

Do you find working with LOGO interesting? You have now learnt to draw different shapes in LOGO. In this chapter, we shall learn some more commands, which would help you to draw faster.

Page 10: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

CLEARSCREEN AND CLEAN COMMANDS

You have studied about the CLEARSCREEN command. What is its use? It clears all the information on the screen and brings the turtle to its home position.

What is the function of CLEAN command? Draw some pictures on the screen and give the CLEAN command. Do you see the difference?

The CLEAN command clears the screen, but leaves the turtle in its current position.

REPETITION OF PICTURES

You have seen how the REPEAT command is used to draw a square, rectangle, triangle, etc. It is used whenever to achieve the same. How? This can be done using procedures.

PROCEDURE

Procedure is a set of commands or instructions. The set of instructions is given a name. By referring this name in any other command, you can execute the set of commands contained in the procedure.

TO AND END COMMAND

A procedure is defined using the TO and END commands.For example, if you want to give commands to draw a triangle as a procedure, you have to type the following.

TO TRIREPEAT 3 [FD 40 RT 120]END

As soon as you type the TO command, LOGO understands that you are giving some procedure commands. Have you got anything on the screen now? No, because the TO-END command does not draw the picture immediately. It stores the set of commands (between the TO and END command) in the name given after the TO command (in this case TRI).Now, type the name of the procedure, TRI. What happens?

In MSWLogo as soon as you type the TO MODE command, LOGO takes the command in a separate window, which is shown below:

You have to type the command and press the Enter or the OK button. This will prompt you for more commands. Once all the commands in the procedure are over, you will have to type the END command, which will close the input mode. Now that your procedure is defined, you can type the procedure name, which will give the desired result.

The procedures may be entered using the File menu option also, as shown.* Click on the File menu You will see a pull down menu with the following options.Click on Edit option. This will prompt you to type the procedure name.

Type the procedure name, for example, TRI and press the OK button or ENTER key.

Page 11: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

This will open the Editor window.

You can notice that the editor automatically contains the TO and END commands. You can type the LOGO commands in between them. After typing the commands, click on the File menu and select the Save and Exit option. This will save the procedure and return the control back to LOGO screen.

To execute the procedure at the Commander Window, type the procedure name (as per this example, TRI) and press the Enter key.

EDITING THE EXISTING PROCEDURE

If you wish to make changes in an existing procedure, click on the File Menu and select the Edit option. Now the Edit Procedure Window will be displayed. Now select the required procedure name from the listed names and press the Enter key or the OK button.

The editor will be opened with the selected procedure and you can do the changes. Save the procedure and execute.

In MSWLogo, the Save command will save all the current procedures, fewer than one file name with the extension as .LOG. Once this LOG file is opened by the LOAD command then all the procedures will be available to you so that you may use them in your LOGO.

Let us create a procedure for drawing a square.

TO SQUAREREPEAT 4 [FD 50 RT 90]END

Now type SQUARE. Do you see a square on the screen?

PROCEDURE WITH PARAMETERS

Now you have learnt to create a procedure for drawing any shape. You will get the picture on the screen only after typing the name of the procedure.Hoe would you draw shapes of varying sizes?

SQUARE

Consider the procedure called SQUARE. In order to get a square of different size, make the following changes.

TO SQUARE: XREPEAT 4 [FD: X RT 909]END

Now type SQUARE. What happens?Did you get any error message stating, NOT ENOUGH INPUTS TO SQUARE? What does it indicate?

Since you have mentioned the size, it cannot draw the square of the required size. Hence the error message.

Page 12: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

In the above procedure, the letter X stands for the size of the square. It is called a parameter. It can be given any input value.

Let us take the value X as 30 and replace it in the procedure. Now type the command as SQUARE 30. This indicates that you want a square of size 30 units. Check what you get on the screen.

Now type the same command three times with 40, 50 and 60 units, respectively. You will get squares of three different sizes.

So, by using the same procedure called SQUARE, you can draw any number of squares of different sizes. This is the advantage of creating procedures with parameters.

RECTANGLE

The procedures can be created with more than one parameter also. Suppose you want o draw a rectangle. You need two values, one for length and one for breadth.

Let us see hoe to create a procedure for drawing a rectangle with two parameters.

TO RECT: X: YREPEAT 2 [FD: Y RT 90 FD: X RT 90]END

Type the above commands, give different values for X and Y. now type the command RECT X Y (by giving different values for X and Y) and get rectangles of different sizes.

POLYGON

What is a polygon? It is a closed shape with many sides. The minimum number of sides in a polygon is three.

If you develop a [procedure to draw a polygon, then it can be used to draw a triangle, square, pentagon, etc.

The sum of the internal angles in a polygon is 360.

To get the angle of each side in any polygon, divide 360 (total angle) by the number of sides in that polygon.

For example, Triangle -- 360/3 = 120 (If all the sides are equal) Square – 360/4 = 90 Pentagon – 360/5 = 72

Now let us create a procedure for drawing a polygon.

TO POLY: NREPEAT: N [FD 20 RT 360/: N]END

Page 13: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The parameter stands for the number of sides. The commands are repeated N times to draw N sides. The angle to be turned each time is 360/N.Now type POLY 3. Do you get a triangle on the screen?Type the command POLY 4. You get a square.You can draw any polygon by just changing the value of N.

THE POTS COMMAND

Sometimes, you tend to forget the names of the procedures created. How can you know the names?

The POTS command (stands for Print Out Titles) will display all the procedure names. The names are listed in their order of creation, i.e., the newest procedure will be listed at the top and the oldest procedure at the bottom.

THE SAVE COMMAND

LOGO can remember the procedures till the software is on. How to make LOGO remember the procedures always?

All the procedures can be saved in the disk using the SAVE command. The SAVE command is given as below.SAVE “name of the procedure”For example, to save the Procedure SQUARE, you have to typeSAVE “SQ”The SAVE command helps to recall the procedures for future use.

THE LOAD COMMAND

How to recall the procedures you have saved in the previous sessions?This can be achieved by loading them into the computers’ memory.Type the LOAD command. This is given asLOAD “name of the procedure”.For example, LOAD “SQ”This brings the SQ procedure into the memory and you can use it for drawing squares.

THE ERASE COMMAND

Try this SQ procedure:

TO SQREPEAT 3 [FD 50 RT 90]END

Now type SQ. what do you see on the screen? You can see a square with three sides and having the fourth side open. This is because you have made a mistake in the procedure. You have typed 3 instead of 4 after REPEAT. How can you change it?

Type TO SQ. this will give a message stating that the procedure already exists.

If you want to erase the SQ procedure and retype the same without mistake, you can do it using the ERASE command.

Page 14: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Type ERASE “SQ”

This will undefined the SQ procedure.

How to verify that SQ is deleted? Type the command SQ. LOGO will display the message “I DO NOT KNOW HOW TO SQ”. Thus you are sure that SQ is erased from the memory.

Now, you can define the SQ procedure again:

TO SQREPEAT 4 [FD 50 RT 90]END

Terms to remember

Procedure: A set of commands or programs that carries out well-defined operations o data specified by parameters.

Parameter: An alphabet given along with the name of the procedure, which will be substituted by any number during the execution of the procedure.

Polygon: A closed object with three or more sides.

Points to remember

The CLEAN and CLEARSCREEN commands are used to clear the contents of the LOGO screen.The CLEAN command will erase all the information on the screen and retain the turtlehead at the current position.The CLEARSCREEN command will erase all the information on the screen and set the turtlehead at its home position.A procedure is a set of LOGO commands defined by TO and END commands.A procedure can be called or referred by any other procedure, like a LOGO command.Procedure with parameter is used to draw shapes with varying sizes.LOGO cannot remember a defined procedure. It remains only till the LOGO software is on.The POTS command will list all the already defined procedure names in their order of creation.To recall the procedure for future use, it must be saved using the SAVE command.The saved procedure can be recalled using the LOAD command.The procedure can be removed or deleted using the ERASE command.

CURVES, WORDS AND LISTS IN LOGO

PICTURES WITH CURVES

You know how to draw objects with straight lines using LOGO. You can also use LOGO to draw many pictures with curves.

Page 15: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

CIRCLES

In the last chapter, you had developed a procedure called POLY to draw a polygon with many sides. Now try this POLYProcedure with the input value as 10.

TO POLY: XREPEAT: X [FD 20 RT 360/: X]END

Type POLY 10.

What do you get on the screen? Does it look a circle? If the circle is not smooth, try the POLY procedure with an input value of 15. Does thus circle look better?

What do you infer from this? As the number of sides of a polygon (the input value) increases, the resulting picture resembles a circle.

ARCS

Do you know what an arc is? It is a part of a circle. It looks like this.

Can you draw an arc? Drawing small curves and then connecting them can make an arc.

Let us try the following:

CLEARSCREENREPEAT 9 [FD 10 RT 10]

This command instructs LOGO to draw a line of 10 units, rotate it by an angle of 10 and repeat the same process 9 times. Check the shape you get on the screen.

Now try the following command.

RT 90EPEAT 9 [FD 10 RT 10]

How does the picture look? Does it look like the petal of a flower? If you change the angle in RT or the unit in FD command, you will get petals of different sizes and shapes.

Try chang9ng the values to get petals of different sizes.

Do you always get a closed petal? Sometimes the two arcs do not meet to form a petal. You will get a closed petal only by covering 90 degrees.

So the general procedure to be adopted isREPEAT N [FD 10 RT 90/N]

If the number of turns is N, then each turn should be 90/N.

By changing the value of the FD command, you can get figures of different sizes.

Page 16: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The procedure for the above command is defined as PET.

TO PET: N: DREPEAT: N [FD: D RT 90 /: N]RT 90REPEAT: N [FD: D RT 90 /: N]RT 90END

Now you can define another procedure to make a complete flower from a petal as FLO.

TO FLO: N: D: CREPEAT: C [PET: N: D RT 360 /: C]END[C = Number of petals]

Type FLOP 9 10 10 and see whether you get a flower with 10 petals.

In the above procedure FLO, you have used another procedure PET.

Thus a procedure can be used as a part of another procedure.

WORDS AND LISTS

You have learnt how to draw pictures using various commands. You have also learnt commands to create you own procedures and the methods of using and saving them in LOGO.

Now let us discuss the commands to be used with characters and strings. LOGO handles three types of data: numeric, string and list.

Numeric data

Numeric data are numbers on which you perform arithmetic operations like addition, subtraction, multiplication and division.

String

String, also called word, is a data with alphanumeric characters. The items in this data are given within quotation marks. For example.“CHENNAI“1998“FILE1“

The number of characters counts the length of each data. For example, in the first data “CHENNAI, the length is 7; in the second data, the length is 4; the third data is of length 5 and the last data is of 0 length, i.e., it is an empty one.

List

Page 17: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

List is a set of words or numbers enclosed inside square brackets. A few examples are given below.

[I AM LEARNNG LOGO][XAVIER GUPTA][A B C D E][2 3 5 7 11]

The number of elements in it counts the length of a list. For example, the length of the first list is 4 and the second list is 2.

THE COUNT COMMAND

The COUNT command is used for finding the total number of characters in a word or total number of elements in a list.

Let us take the first example “CHENNAI. To count the total number of characters in this word, type the following command.PR COUNT “CHENNAI

You will get 7 on the screen. This indicates that the word has 7 characters in it. The PR command is used to print the result. Take another example. Type this command.

PR COUNT [I AM LEARNING LOGO]

You will get 4 on the screen. This indicates that this list has 4 elements in it. The COUNT command can be used with other commands also. For example, if you typeFD COUNT [LOGO IS VERY SIMPLE AND INTERESTING]

The turtle will move 6 units in the forward direction.

THE FIRST COMMAND

This command gives the first character of a word, first digit of a number or first element of a list. Hence a number, word or list should follow the FIRST command.PR FIRST 1998This will print the result as 1.

PR FIRST “COMPUTERThis will print result as C.

PR FIRST [MY TEACHER IS VERY NICE]This will print the result as my.

THE LAST COMMAND

Can you guess what the LAST command does? Yes, you have guessed it right! It gives last element of a list, last character of a word or last digit of a number. This command also takes a number, word or list as input.

PR LAST 1998This will print the result as 8.

Page 18: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

PR LAST “COMPUTERThis will print the result as R.

PR LAST [MY TEACHER IS VERY NICE]This will print the result as nice.

THE BF COMMAND

BF stands for But First. This command gives all the elements except the first as the result.

PR BF 1998This will print the result as 998.

PR BF “COMPUTERThis will print result as OMPUTER.

PR BF [MY TEACHER IS VERY NICE]This will print the result, as teacher is very nice.

THE BL COMMAND

BL stands for But Last. This command gives all the elements except the last.

PR BL 1998This will print the result as 199.

PR BL “COMPUTERThis will print the result as compute

PR BL [MY TEACHER IS VERY NICE]This will print the result as my teacher is very

THE WORD COMMAND

If you have two numbers, you can add them using the SUM command. Let us see what is the use of the WORD command.

Type the following commands and note the result from LOGO.PR SUM 5 6PR WORD 5 6

Have you got the results? What is the result from the first command? It is 11. LOGO has calculated the sum of 5 and 6 and given the result as 11.

What is the result of the second command? Is it 56? Can you guess what LOGO has done in the WORD command? It has simply joined both the numbers, instead of adding them. Hence the result 56.

Thus, you can join two words as below.PR WORD “AB “CDYou will get ABCD

Page 19: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The WORD command also join one word and one number.PR WORD “ 1You will get A1.

Note: The WORD command can take only a word or number as input. It cannot join two lists.

THE SE COMMAND

This command can join two numbers or words and make a sentence. It will leave a blank space between the numbers or words.

For example, try the following:PR SE 5 6This will give the result as 5 6

PR SE “AB “CDThis will give the result as AB CD

PR SE “A 1This will give the result as A 1

Terms to remember

String: A data with alphanumeric characters given within quotation marks.

List: A set of words or numbers enclosed inside square brackets.

Points to remember

LOGO can be used to draw pictures with straight lines and curves.LOGO handles three kinds of data: Numeric, Word (String) and List.The COUNT command will take a number, word or list as input. It can count the total number of characters in a word, digits in a number or elements in a list.The FIRST command will give the first digit of a number, the first character of a word or the first element of a list.The LAST command will give the last digit of a number, the last character of a word or the last element of a list.The BF command will return all the input elements (word, number or list) except the first.The BL command will return all the input elements (word, number or list) except the last.The WORD command will join two digits or characters to make one word. It cannot join two lists.The SE command will join two digits or characters to make one sentence by leaving a blank space in between.

Programming in LOGO

What is a LOGO Program?

Till now, we were drawing pictures by using individual LOGO commands, some pictures needed less number of commands, and some needed more. If you put a few commands in a file for later execution of the commands, the collection is called a Program. Instead of

Page 20: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

giving the commands one by one, just type the program’s name and press Enter. The program will start running and all the commands in it will be executed one after the other. Let us study the example below,TP PENTAGONREPEAT 5 [FD 30 RT 72]END

The name of the above program is PENTAGON. Following some rules, you may give any name of your choice. The first line of a LOGO program always starts with the word “TO” follow by the program name. The desired commands are written second line onwards. The program ends with the word “END” in the last line. This indicates to LOGO that the program has ended. The usual preparatory commands CS and ST in the beginning and HT at the end need not be included in a program. To draw a pentagon now, you have only to say,? CS ST? PENTAGON? HT

Note that, you have used the name PENTAGON in such a way as if it were a LOGO command; as if one more command has been added to the LGO language. The advantage here is that, you have written the program beforehand. Now, when you are drawing the pentagon, you do not have to think at all how you will draw it using which commands. You have done the thinking earlier at leisure. If you want to draw a smaller or larger pentagon, edit the PENTAGON program suitably giving it a new name and use the new program just like a command.

How to Write a Program

Now, we will learn how to write a program. A program contains commands. These are to be inputted in the program file by using a text editor. Recall the use of DOS Edit command. This command can be used for creating program files. But, still easier is to be use the text editor in LOGO itself. If you press F1 key in LOGO, you wou8ld get the LOGO editor screen.

The lines at the bottom of the screen tell you about the function of some keys. For example, you learn here that F2 key takes you to the split screen, F9 is to be used for loading old programs in the editor screen and F10 saves the program you are writing.

Using this editor, we will now write the program Pentagon,TO PENTAGONREPEAT 5 [FD 30 RT 72]END

Notice that, the program starts with the word “TO” followed by the program name. The commands in the program follow this first line. The program ends with the word “END”. All LOGO programs have to be written this way. If you want to write a program for drawing the picture of a flower, you may write FLOWER after TO in the first line. The second line onwards will contain the commands for drawing the picture. The last line will contain END.

Notice that, the cursor rests at the top corner of the editor screen. Type the first three lines of the PENTAGON program one after the other. The characters are to be typed at the position of the cursor and it will shift to the right with typing of every character. After typing

Page 21: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

each line Enter key has to be pressed. If you make any mistake, you can correct it by using Arrow, Backspace or Del key. You may move the cursor to different positions in the screen by using the four Arrow keys.

Pressing the Backspace key once will delete the previous character. To delete a line, bring the cursor at the beginning of the line and press the Del key. If the program is large, it may not be accommodated fully on the screen. You will see only a part of it. To see he rest of the program pages, you have to use the PgDn key. To see the previous pages of a program, PgUp key has to be used.

Saving and Loading a Program

After you finish a program, pres F10 key to save it permanently. LOGO will then ask the program file name from you,Save File Name <Enter>:

Now type a suitable name for your program file. A good name gives an idea about the content of the file. The file will be saved on pressing Enter after the name. Remember, you have to type the name of the program file and not the name of the program here.

Pressing F2 key now will tale you back to the drawing screen where you will find the display,PENTAGON DEFINED

This means that the LOGO program now knows about the PENTAGON program. To express this in another way, the PENTAGON program has now been loaded in the RAM for execution. If you type PENTAGON at the LOGO prompt now and press Enter, the program would be executed and a pentagon would be drawn. It is as if you have used the name of the program like a LOGO command. You could have come to the drawing screen by pressing F2 key without saving and then could have run the program. But, in that case, you would have lost the program. If you wanted to draw the same picture again later, you would have to write all the commands again.

Suppose, you have written and saved the PENTAGON program. Later, after starting LOGO, you have typed PENTAGON at the LOGO prompt and pressed Enter. You will expect the picture of the pentagon to be drawn. Instead, you will get the display,This is not a LOGO procedure: PENTAGONTop level

You know that you saved the program, but what happened then? The answer is, though the program is in your hard disk, LOGO cannot read the hard disk directly until you load the program. Loading copies the program from the hard disk to the RAM. Only then can LOGO execute it and draw the desired picture. To load a program, you have to press F9 key. LOGO will then ask the name of the program file to be loaded. It will display in the last line,Load File Name <Enter>:

Now type PENTAGON and press Enter. LOGO will display,? : Loading file PENTAGON.LGOPENTAGON Defined? _

Page 22: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The PENTAGON.LGO in the first line is the name of the program file. When you save, LOGO by itself adds the extension .LGO to the file name. the PENTAGON in the second line is the name of the program. There is no relation between these two names. A program may have the name FLOWERPOT, but its program file name may be FLRPOT (.LGO extension will be added by LOGO). At the time of saving and loading, you have to use the program file name. You may also load a program by pressing F9 at the edit screen.

While working in LOGO, if you want to see the list of programs in your directory, you have to give the command (DOS [Dir]) at the LOGO prompt. By the command – (DOS [Dir A:]), you can see the directory of your floppy disk in the same way. You may also give other DOS commands inside the brackets.

Program Name

The program name has to be written after “TO”. This name is different from the program file name. The name of a program for drawing the picture of a flowerpot may be FLOWERPOT. But, when you save it in the disk, you cannot use such a long file name. This is because the file names in DOS cannot exceed eight characters. Suppose, at the time of saving, you have named the file as FLRPOT. So, the program name in this case is FLOWERPOT, but the program file name is FLRPOT. When you run this program from the drawing screen, you have to use the name, FLOWERPOT, but, at the time of editing, saving or loading you have to use the name FLRPOT.

Remember, the name of a program file is formed just like other DOS files. Let us now learn the rules of forming the program names.

Rules of forming Program Names

Using letters and numbers only forms program names. Special characters such as, #, +, \+etc. cannot be used. A program name cannot have a space in it. The following are all valid LOGO program names,SQUARE, FLOWERPOT2, P, 3FLOWERSIn a program name, only characters can be used, but a name containing only numbers is not a valid name. At least one character must be there in a program name.A program name has to be unique in the directory. You cannot use a command name as a program name. For example, the name FD is an invalid program name.

Changing or editing programs

You may want to change the PENTAGON program any time while you are working on the drawing screen. First you have to press F1 key to bring the edit screen and then F9 key to load the program. The last line of the screen will say,Load File Name <Enter>:

Type PENTAGON and press Enter. The program lines will be displayed on the edit screen. If you want to reduce the size of the pentagon, change the program accordingly and save it. If you do not save, LOGO would not remember the changes in the program. Notice that, while loading and saving, you have to use the program file name.

Another easy method for editing the program PENTAGON is to give the following command at the LOGO prompt,

Page 23: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

? EDIT PENTAGON

You will then get the PENTAGON program in the screen for editing.

More Programming in LOGO

Programs within a Program

You have written all the programs till now by using only LOGO commands such as FD, BK, and REPEAT etc. but in your program, you could also have used the names of other LOGO programs just like any LOGO command. This is what we call “using programs within a program”. We will learn how to do this. We will also learn the use of variables and the technique of recursion in writing a LOGO program.

A LOGO program for drawing a flower is,TO FLOWER

REPEAT 10 [FD 4 LT 6]LT 75REPEAT 5 [FD 3 LT 9]RT 180REPEAT 8 [REPEAT 10 [FD 3 RT 9] RT 135]END

The name of the program is FLOWER. You know that the first line of a LOGO program starts with the word “TO” and then the program name follows. The subsequent lines contain the commands that do the main job and the last line always has the word “END”. This indicates to LOGO that the running program has finished its job. Also, CS and ST in the beginning and HT at the end are not normally included in a program. These three commands are gives when the program is used as a command at the LOGO prompt.

The program to draw a pot for keeping flowers is,TO POTRT 70REPEAT 20 [FD 3 RT 2]RT 140REPEAT 20 [FD 3 RT 2]LT 120FD 45LT 80FD 43LT 80FD 45END

By the following commands, you may now draw the flowerpot adorned with a flower,? CS ST? FLOWER? PU? HOME? LT 90? FD 27? RT 90

Page 24: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

? PD? POT? HT

See how easily you have drawn the picture by only a few commands. This has become possible because you have already written the programs POT and FLOWER. While drawing the flowerpot, you have used these two program names just like any other LOGO commands. You have not thought about the details of drawing the flower or the pot at all. You have completed these jobs beforehand. If you want to make flower bigger or smaller, you just have to change the program called FLOWER. No change is needed in the commands in which you have used this program FLOWER.

You have given the commands for drawing the flowerpot directly at the LOGO prompt. Instead, you could have put these commands in a program file FLRPOT and used this new program later on. Give a name FLOWERPOT to this program. We have already the name of he program file as FLRPOT.

So, the program file FLRPOT contains “TO FLOWERPOT” in the first line instead of “CS ST”, hen the commands as above (left of Fig. 9.1) and finally “END” instead of “HT” in the last line.

Suppose, you want to draw the picture of your room by a program. In this program, just use the name FLOWERPOT to insert the picture of the flowerpot suitably in the overall picture. Of course, you have also to write the programs for drawing pictures of the other objects I your room.

The above figure shows that, within the program for ROOM, the program FLPOWERPOT has been used. Within program again, the programs POT and FLOWER have been used like LOGO commands. These two programs POT and FLOWER are called the subprograms of the program FLOWERPOT.

Remember, unless you load all of these three programs, you will not be able to run the FLOWRPOT program.

Advantages of using LOGO Programs

Let us now try to understand the advantages of using LOGO programs,Drawing a picture by using subprograms need fewer commands. A program used for drawing a picture may also be used for drawing another picture. This is called Program Reuse. For example, you could have put your FLOWER in a POT or in a VASE. You have only to write one program for VASE and another for FLOWERVASE. You do not have to write FLOWER program again. Just use it again in the program FLOWERVASE. A correctly written program may be used in future for any length of time.4. A program name may be used as a LOGO command for drawing pictures. You may go on increasing the number of LOGO commands this way by writing more and more programs. This takes the LOGO languag3 more powerful. After some time of working in this manner, you may build a Program Library for drawing standard pictures. Using these programs, you may be able to draw larger and more complicated pictures easily.It is difficult to change an already drawn picture without redrawing. But, if a picture us drawn by using a program, you may change the program just a little bit and have the changed picture. As the previous commands are available in the program, you do not

Page 25: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

have to retype the commands. Thus, pictures drawn by using programs are very easy to change.To draw a large picture, you have to first identify the different types of objects in it. Then, you have to write a program for drawing each of these types of objects and use these appropriately in the larger picture. For example, for drawing a picture of the flowerpot adorned with flower, we have written the programs for the pot and the flower first. Then, we needed only to use these two programs as commands and get the final program FLOWERPOT for the larger picture.

It is not easy to draw a large picture at one go. It is much easier to draw the parts and then combine to get the whole. It is easy to draw the flower and the pot separately and then combine these two to get the flowerpot. When you draw the flower, you do not have to think at all about how to draw the pot, or for that matter, the complete flowerpot. This is liker splitting a complex puzzle into small parts and gets the solution of the original puzzle by solving the smaller parts and combining the results.

This technique of splitting a large job into smaller tasks in steps and combining the results of these smaller tasks to get the end result is called Structured Programming. This method of working has an added advantage. Even your friend can do a few smaller subprograms and thereby share you’re your workload. It is always easier to do a job in a team rather than doing it alone.

Not only LOGO, but any good programming language also has these advantages.

Use of Variables in a LOGO Program

A program to draw a square is,TO SQUAREREPEAT 4 [FD 20RT 90]END

Each side of this square is 20 turtle steps long. If you want to draw another square with sides 30 steps long, you have t write another program. If you had used Variables in writing the original program, the same could have been used for drawing smaller or bigger squares also. No new programs would have been required.

Any variable has a Name and a Value. The computer reserves a space in the primary memory for this variable. The name of this space is in the name of the variable. The value of the variable is stored in this space. As this value changes from time to time, it is called a variable. By the following program, you will be able to draw squares of various sizes. The size of the square will depend on the value of the variable SIDE.TO SQUARE: SIDREPEAT 4 [FD: SIDE RT 90]END

Let us see how you can actually draw squares by this program,? SQUARE 20? SQUARE30? SQUARE 40? _

Page 26: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

You have given the value of the variable SIDE as 20 in the first command, 30 in the second and 40 in the third. The picture drawn is as shown above. The first square drawn was of side length 20 turtle came back to its Home. Similarly, the second and the third squares were come to rest as its Home.

The writer of the program has given the name SIDE to the variable and while running the program; you have communicated the length of the side to the program through this variable. The same job would have been done even if the name of the variable were LENGTH instead of SIDE.

Only one variable has been used in the above program. You may also use more than one variable in a program. In the program below we have use two variables, LENGTH and BREADTH,TO RECTANGLE: LENGTH: BREADTHREPEAT 2 [FD: LENGTH RT 90 FD: BREADTH RT 90]END

To run this program, we have to give the values of the variables as below,? RECTANGLE 20,10? RECTANGLE 30,20? RECTANGLE 40,30? _

The variable values, while using the program, have to be given in the same sequence of variable names written in the first line of the program. The variable LENGTH appears first in the RECTANGLE program, and so, the first value in the RECTANGLE commands (Program Calls) above, will be assigned to the variable LENGTH. By the same logic, the second value I the RECTANGLE commands will be assigned to the variable BREADTH, which is the second variable in the RECTANGLE program.

In the last RCTANGLE command, LENGTH will have value 40 and BREADTH 30.

You may also create a new variable by the command MAKE. This command has an additional advantage. With this command, you may assign a starting value to a variable and may also change its value within the program. Let us make this point clear through an example,TO SPIRALMAKE “STEP 10REPEAT 12 [FD: STEP RT 90 FD: STEP RT 90 MAKE “STEP (: STEP + 10)]END

The variable STEP stared with the value 10 in the MAKE command at the second line. Inside the REPEAT command, twice the turtle went straight and hen turned. After that, the value of STEP increased by another 10. These steps were repeated 12 times in total to form the rectangular spiral.

Recursion

Recursion means using a program within itself. We will learn the command IF along with recursion in this section. Let us try to understand this by drawing the picture of our Spiral using recursion.TO SPIRALNEW: STEP

Page 27: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

REPEAT 2 [FD: STEP RT 90]IF: STEP > 110 THEN STOPSPIRALNEW: STEP + 10END

In the first line of the above program, there is no starting value of the variable STEP. Can you say wherefrom the program will get this value?

When running the program, suppose you have given the starting variable value 10 with the program name. In the second command, the turtle moves straight twice and then take a right-angled turn as before. The IF command at the third line means, if the value of STEP becomes more than 110, then the program will stop. Otherwise, the command at the fourth line will be executed. In this case, any other command before the End and after the IF command will also be executed.

Let us now take a close look at the command in the fourth line. Notice that, this line contains the same program name. This is recursion. It means, the program will start executing from the first line again. The only difference this time will be in the value of the variable STEP. This will have a value increased by 10 when the program runs a second time. This value will further be increased by 10 during the third execution.

The SPIRALNEW program will run again and again in this way. With every execution, the value of STEP will be increased by 10 from its previous value. In the twelfth such execution, the value of STEP will be 120. Then only the IF command at the third line will find this value more than 110 and will immediately stop the program. The REPEAT command will be executed 12 times in total. The condition: STEP > 110 in the third line is called the Terminating Condition and is used for stopping the program when its work is properly finished. If you make any error in setting this condition, the program execution would be seriously erroneous.

In the IF command, you could have used: STEP = 120 instead of: STEP > 110. This changed program could have drawn the same picture also. But, this changed program would have had a serious flaw hidden in it. If, by mistake, you had given the command SPIRALNEW 5 while using this changed program, the variable STEP would never have been equal to 120. The program would have continued to run for infinite time. This is called an infinite loop condition and is the worst mistake a programmer can commit.

Examples

We will draw a picture of three balloons first,TO 3BALLOONSLT 30 FD 50 LT 60BALLOONFD 45 LT 90BALLOONRT 30 FD 50 LT 120BALLOON ENDTO BALLOONSETSCRUNCH 3REPEAT 60 [FD .4 RT 6]PU HOME PDSETSCRUNCH 1

Page 28: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

END

Now, we will draw circles within other circles,TO CIRCLES: STEPREPEAT 3 [CIRCLE: STEP MOVE1 MAKE “STEP (: STEP - .3)]ENDTO CIRCLE: DISTREPEAT 360 [FD: DIST RT 1]ENDTO MOVE1PU RT 90 FD 17 LT 90 PDEND

If you give the command CIRCLE 1 at the LOGO prompt, the picture drawn will be as shown above. First time, STEP or DIST will have value 1. Second time, the value will be reduced to 0.7 and third time to 0.4. The more this value will reduce, the smaller will be the circle. Every time, the CIRCLES program will pass on the value of the variable STEP to the value of DIST in the CIRCLE program. These two variables will always have some values.

LOGO Arithmetic

LOGO Arithmetic

You may do many more things in LOGO than drawing pictures. We will learn now how to do LOGO arithmetic. You may do addition, subtraction, multiplication, division and a few other arithmetic operations in LOGO. Before you learn how to do thee, let us see how you can display words on the screen. He command to display on the screen is PRINT or PR in short. If you give the command, Pr “Welcome, the computer will display the word “Welcome” on the screen. To see the result of the sum of two numbers 4 and 3, you have to give the command,? PR SUM 4 37? _

LOGO will show the result just below the command. You may do the same job by the command PR 4+3. To add more than two numbers and see the result, you may use the following command,?PR (SUM 45 56 9)110?PR 45+56+9110?_

A first bracket is to be used for adding more than two numbers by the command SUM. Within the first brackets, any number of numbers may be added by the command SUM. Whatever numbers follow SUM will be added by LOGO and the result will be given to the command that called SUM. In the case of our example, PR is the calling command and the command SUM is the called command. Instead of PR, the calling command could very well have been FD, BK etc.

Page 29: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

The same result may be obtained without the help of the SUM command by directly summing up the numbers. In this case, remember, writing 45 +5 will be wrong but 45+5 or 45 + 5 will not be.It is easier to use no space between the two characters. This eliminates chances of error.

You may further use – for subtraction, * for multiplication and / for division. These are shown in the example below left. Note that, we have not used any space between the numbers and -, * or / symbols.

? PR 69-5-4 ? PR PRODUCT 5 760 35 ? PR 4*5*8 ? PR (PRODUCT 6 7 3) 160 126? P-R 45/6 ? _7.50? _

Remember, you should never divide a number by zero. This will make the result of division infinite that no computer can handle. This is another of the most serious errors a programmer can commit. You may also do multiplication by the command PRODUCT in the same way as SUM, as shown above right. To multiply three numbers by PRODUCT, you have to enclose the expression within first brackets. Lie the SUM or + command, you may multiply many numbers by using the PRODUCT or the * command.

Till now, we have used only one type of arithmetic command at one time. It is also possible to combine the arithmetic command as per your requirement. For example, you may add two numbers, multiply the result by a third number and display the result. This is shown in the next example. ? PR (69-5-4)*5300? PR 69-5-4*544? PR 10+(4*5*8)170? PR 10+45/617.50? _

In the first line above, the first expression of (69-5-4) produces the result 60. 5 to produce the final result of 300 further multiply this. Notice that, in the third line, the bracket is not used and the final result is different, though the expressions are similar. In this case, LOGO evaluates first 4*5 separately and uses the result 20 for subtraction. The resultant expression becomes 69-5-20 in this case. This phenomenon is called operator precedence. Let us elaborate it a bit further.

In an arithmetic expressing, the *, -, + or/ symbols are called operators and these indicates to LOGO the operations of addition, subtraction, multiplication and division, respectively. In an expression where different types of operators are used, LOGO first evaluates the * and / operations. It means, wherever it finds multiplication or division, LOGO performs those calculations first. At the next stage then, LOGO performs the additions and subtractions.

Page 30: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

So, we say, * and / have equal precedence relative to each other. The operations + and – also have equal precedence relative to each other. But, the operations * and / both have higher precedence compared to the operations + and -.

Notice that, the operator first bracket has overridden this normal precedence relation in the first of the above examples. This is the specialty of the bracket operator. Whatever expressions are enclosed within the first bracket will be evaluated first and only then the rest of the expressions will be evaluated. So we say that, in an arithmetic expression, the first bracket operator has the highest precedence, followed by the * and /, and finally, by + and -. To understand the mechanism of precedence, you should experiment yourself.

If we change the expression 10+(4*5*8) by adding 10 later, we get the expression, (4*5*8)+10. this does not work properly. When he first brackets are removed, you get the desired result of 170 again. In LOGO, you should not use the bracket operator where it is not necessary.

Finally, a special result is, with an arithmetic command, if you do not give the PR, you would still be able to see the result. But, an extra word RESULT: would be displayed before the actual result, ? 5+5RESULT: 10? _

Let us try to understand this. If you do not give PR, even then LOGO will calculate the actual result. The job of PR is to display, but not to calculate. It displays numbers, words, calculation results or anything given to it. Instead of PR 20+30, you may very well use the command FD 20+30. This will move the turtle forward by 50 steps. Similarly, you may use FD 30-20 or FD 30*5 or FD 120/4 also. LOGO first evaluates the expression and then only passes the result of evaluation to the command preceding the expression.

LOGO has also got facilities for calculating the quotient and the remainder of a division. As you know, quotient is the result of a division. The commands for doing these are QOUTIENT and REMAINDER. The first three commands below are examples of these two. In the third and fourth command, a new command INT is used for showing the integer part only.? PR REMAINDER 45 63? PR QOUTIENT 45 67.50? PR INT QOUTIENT 45 67? PR INT 40.9640? _

In the second result, the quotient is a fraction. To show integer part only, INT command is o be used. He two commands for showing numbers in integer form are, INT and ROUND. These two commands are used below,? PR INT 40.9640? PR ROUND 40.9641

Page 31: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

? PR ROUND 40.4940? _

A number may have two parts, integer and fraction. ROUND truncates the fraction part if it is less than 0.50. If the fraction part is equal to or more than 0.50, the integer part is increased by 1 and fraction is eliminated. Rounding is an approximation to reduce the number of decimal digits.

On the other hand, INT always truncates the fraction part and keeps the integer part only.

RANDOM is an interesting command that operates on numbers,? PR RANDOM 123? PR RANDOM 1210? PR RANDOM 121? _

The function of the above RANDOM command is to output a number between 1 and 12 randomly without following any rules. Randomly means, next number that will be displayed is unpredictable. The umber to be displayed follows no pattern. Using this command, you may write a program for playing a number guessing game with your friend. This command may be used with other command also as shown in he next example.? REPEAT 4 [PR RANDOM 12]17611? _

This time, you will get four random numbers instead of one.

There is another command IF, by which you can compare two numbers to see which one is the larger.? IF 10>15 THEN PR “GREATER ELSE PR “LESSERLESSER? _

10 is not larger than 15 and so the word “LESSER” is displayed. LOGO evaluates the condition is true under IF and executes the expression under THEN if the condition is true. If it is false, the expression under ELSE is executed.

Examples

1. The program below will add any two numbers,TO ADD: NUM1: NUM2PR: NUM1 +: NUM2ENDTo add the two numbers 145 and 67, you have to give the command,? ADD 145 67

Page 32: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

212? _

2. The ADD program above adds two numbers and displays the result on the screen. Instead of displaying by PR, if we had used OP command, the result would not have been displayed, but it would have been available to any other command for its use. It would have been available in RAM. Let us see how this happens,

TO ADD2: NUM1: NUM2OP: NUM1 +: NUM2ENDThis ADD2 program transfers the result of the addition to the RT command, ? RT ADD2 20 30

The OP command in ADD2 program does he addition and outputs the result to the RT command. RT takes the value of the addition and executes accordingly. The result of addition is not displayed; it merely turns the turtle right.

If we used PR instead of RT in the command above, then the result would have been displayed. You would get the same result by using PR instead of OP in ADD2 program and running ADD2 from LOGO prompt. But, in this case, you would have lost the flexibility of passing the result of addition to any command like LT, BK or FD.

3. The PR command first displays on the screen and then moves the cursor to the prompt in the next line. Another display command TYPE also displays on the screen, but does not shift the cursor at all. It waits in the same line and same position for the next print command. We will write a small program for calculating the cost of materials by using this command.

The COST program COST program runTO COST: RATE: QUANTITY ? COST 5 30TYPE [COST =] COST = 150PR: COSAT *: QUANTITY ? _ END

Playing with Words in LOGO

So, we now know how to draw pictures and how to do arithmetic sums in LOGO. But, LOGO can do even more for you. We will learn here how to play with words in LOGO.

Like sums, LOGO has various textual commands. With these you may transform words. After transforming, as before, you will display the results by using the PR command.

If no textual commands are used in a command, LOGO will directly display the text given with PR. When textual commands like BF, BL are used, LOGO first executes those commands and then passes the result on to the Pr for display.

We will learn here the commands for inputting, dissecting and concatenating words. In the process, we will build word puzzles also.

Working with Words

Page 33: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Instead of a number, a word may be given with PR. When you give the command, PR “Welcome, LOGO will find that no calculation is to be done. It will hand over the word straightway to the command PR that will display it on the screen. A single word can be displayed by the command from PR “,? PR “WelcomeWelcome? _any such word may be displayed through PR,? PR “3FLOWERS3FLOWERS? PR “22NOV198622NOV1986? PR “TODAYTODAY? _

All these are single words. You cannot use the special characters -, +, *, / within any of these words. More than one word may also be displayed by using PR. A few words together form a sentence. “WHST IS YOUR NAME?”“THIS IS YOUR BIRTHDAY”, “ROSE ISRED” are such sentences. We will display these on the screen by the commands below. The sentences are to be enclosed between third brackets or parenthesis,? PR [WHAT IS YOUR NAME?]WHAT IS YOUR NAME?? PR [THIS IS YOUR BIRTHDAY]THIS IS YOUR BIRTHDAY? PR [ROSE IS RED]ROSE IS RED? _

The content within the parenthesis is called a List in LOGO terminology. The objects in the list are called Elements. The elements may be words or may be other lists or may even be other types of objects. Recall our REPEAT command, REPEAT 360 [FD 1 RT 1]. Here, the contents within the brackets formed a list. In this chapter, we will work only with words.

The list concept of LOGO is a powerful one. You have the flexibility of putting anything you like within parenthesis to make it a list. You may even put other lists within a list. With a list you have the capability to process the elements individually or all together like you have done in PR [ROSE IS RED].

Dissecting Words

To get the first or the last character of a word, FIRST or LAST command is to be used,? PR FIRST “LOGOL? PR LAST “LOGOO? _

The first letter L and last letter O will be output by the above commands. Note that, in the first line, FIRST command is executed first. The result produced is the letter L. this result is given to PR for display.

Page 34: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Similarly, you may get the letters excluding the first or the last letter by the commands BUTFIRST and BUTLAST, the former meaning “all the rest excluding the first” and the latter “all the rest excluding the last”. Examples of these two commands are given below,

? PR BUTFIRST “LOGOOGO? PR BUTLAST “LOGOLOG? _

The above two commands may be used in shorter form as BF or BL. In all these word-dissecting examples, only single words are used. This is because we have used “along with the words. For multiple words or sentences, we may use the same commands if we enclose the words within parenthesis.

If we enclose a few words within parenthesis, the result becomes a list. The words within the parenthesis are the elements of the list. In this case, the BF and BL commands operate on the elements of the list and not on the characters of the words. Note that, for BF “LOGO command, BF operates on the characters of the word, which are the elements in this case. The action of BF and BL on a list of words is shown in the next example.? PR FIRST [HAPPY BIRTHDAY TO YOU]HAPPY? PR LAST [HAPPY BIRTHDAY TO YOU]YOU? PR BF [HAPPY BIRTHDAY TO YOU]BIRTHDAY TO YOU? PR BL [HAPPY BIRTHDAY TO YOU]HAPPY BIRTHDAY TO? _These commands FIRST, LAST; BF and BL may even be used one after the other.? PR FIRST BF [ROSE IS RED]IS? PR LAST BL [FOX IS A CLEVER ANIMAL]CLEVER

In the first example, the BF command and not the FIRST command works first. BF returns the result, {IS RED]. When the action of BF ends, the resultant command looks like,PR FIRST [IS RED]

When the action of FIRST finishes, we get the answer “IS”. In the second example, BL works first and returns the result [FOX IS A CLEVER] to LAST.

The COUNT command gives you the number of characters in a word or the number of words in a list,? PR COUNT “SUNDAY6? PR COUNT [THIS IS SUNDAY]3? PR COUNT [APPLE GUAVA MANGO CHERRY]4

Page 35: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Similarly, by the ITEM command you get a specific letter of a word or a specific word of a sentence. To get the second word of a sentence THIS IS SUNDAY, you have to use the ITEM command,? PR ITEM 2 [THIS IS SUNDAY]IS? PR ITEM 3 [MANGO ORANGE BANANA GUAVA]BANANA? _

Concatenating Words

By the WORD command, you may add or concatenate one word to another and form a new word. The next command will add the word “DAY” to the word “SUN” and form the new word “SUNDAY”. Remember, you cannot concatenate more than two words by this command and concatenation is done without keeping any spaces between the two words. Also, none of the strings to be concatenated may be a sentence or a collection of words. Only two words may be concatenated by this command. Not that, an individual word such as SUN is preceded by the symbol “, while a sentence such as TODAY IS SUNDAY is to be enclosed within parenthesis.? PR WORD “SUN “DAYSUNDAY? PR WORD “FOOT “BALLFOOTBALL? _

Words may also be concatenated by the commands FPUT and LPUT. Each of these commands will have two strings that are to be concatenated.

The first string has to be a single word. The second string may be another word or may even be a sentence or list. FPUT puts the first word at the beginning of the second string and LPUT puts it at last. But while concatenating, a space is introduced in this case. You will understand this from the next example.? PR FPUT “MY [NAME IS RUBAI]MY NAME IS RUBAI? PR LPUT “ANINDYA [MY NAME IS]MY NAME IS ANINDYA? PR LPUT “APARNA [MY FRIENDS ARE SMITA BONNY]MY FRIENDS ARE SMITA BONNY APARNA? _

The shortcomings of these two commands are the same. These cannot concatenate two sentences or lists. The command for doing this is SENTENCE or SE in short,? PR SE [FOOTBALL IS A] [GREAT GAME]FOOTBALL IS A GREAT GAME? PR SE [WOULD YOU] “COMES?WOULD YOU COME?? PR SE “I [PLAY CRICKET]I PLAY CRICKET? _

Conversing with the Computer

Page 36: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Like every other job, you will need a program to converse with the computer. Conversing with the computer means, the conversing program will run in the computer and will display questions in the screen. You will answer the questions by inputting the answer through the keyboard. The computer will read this answer and again give a response. You must have guessed that a part of the text that the computer tells you must have been put in the program beforehand. The computer from your inputs will form the rest.

The commands READCHAR (RC in short) and READLIST (RL in short) allow you to give these inputs and also transfer the input information to the program. Only one character may be inputted through RC. So, we have RL command for inputting a list or a sentence. Let us try to understand this.

We will write a program that will first ask you the question, WHAT IS YOUR NAME? Suppose, you are TINKU and so you will input TINKU in response to the question. On reading this input from you, the program will then say, GOOD MORNING TINKU. This is what we call conversing with computer. It is as if the computer is talking to you. The program below will do this job.TO GREETPR [WHAT IS YOUR NAME?]MAKE “REPLY RLPR SE [GOOD MORNING]: REPLYEND

The first PR command displays the question. A variable REPLY is created by the MAKE command. Because of the RL command, the program will wait for your reply. Your input will be the value of the variable REPLY.

The SE command will form the computer reply by using the value of the variable REPLY. Finally, the second PR command will get this sentence from SE command and will display it on the screen.

You may create many interesting conversations with the computer in this way.

Examples

1. Now, we will write a program of puzzle. The computer will ask you to choose and memorize a number between 1 and 10. When you are ready, the computer will again tell you to add 2 to the number you have thought and multiply the result by 3. Finally, it will ask you to subtract 3 from the last result. You have to input this final result to the computer. Getting your input, the program will tell you the original number you had chosen.TO RIDDLEPR [CHOOSE A NUMBER BETWEEN 1 & 10. READY?]RLPR [ADD 2. MULTIPLY BY 3. SUBTRACT3. READY?]RLPR [WHAT IS THE RESULT?]MAKE “ANS RLMAKE “NUM FIRST: ANSTYPE [YOUR NUMBER IS =]PR (: NUM – 3) / 3END

Page 37: LOGO - Holistic Healing  · Web viewWe speak and hear many languages such as Hindi, English, Marathi, Gujarati, Kannada, and Tamil etc. Similarly, there are different types of computer

Notice that, the variable ANS in the command MAKE “ANS RL is a list. You cannot do any calculation with it. Your input is the only element of this list. That is why we needed the second MAKE command for extracting the desired number from the list.

The RL after the first question halts the program to give you time to choose the number. If you input anything to indicate that you are ready, the program will move forward and ask the second question. The value of input to RL will not be used directly. The inputting action will only move the program forward to the next command that is a PR here. Let us see how the program actually solved the riddle.

Suppose, you chose a number N. then, your result R would be,R = [(N+2) *3] –3Or, (N+2) = (R+3)/ 3Or, N= [(R+3)] / 3] –2 = (R-3) /3

2. This time, we will write a program for a number guessing game. The program will ask, WHAT NUMBER BEWEEN 1 AND 20 CHOSEN? You will guess the number computer has chosen if it is correct, the computer will display YOU HAVE WON. If not, it will display YOU MHAE LOST.TO GUESSPR [WHAT NUMBER BETWEEN 1 AND 20 CHOSEN?]MAKE “ANS RLMAKE “NUM RANDOM 20TYPE [THE NUMBER COMPUTER CHOSE IS =]PR: NUMIF: NUM = FIRST: ANS THEN PR [YOU HAVE WON] ELSE PR [YOU HAVE LOST]END

3. Now we will write a program DRAWINGS that will first ask, DO YOU WANT A SQUARE (S) OR A CIRCLE ©? If you input S, the program will ask next, HOW LONG IS THE SIDE? Instead, if you input C, it will ask, HOW LONG IS THE STEP? On your input, the desired picture will be drawn.TO DRAWINGSPR [DO YOU WANT A SQUARE (S) OR A CIRCLE ©?]MAKE “CHOICE RCIF: CHOICE = FIRST [S] THEN PR [HOW LONG IS THE SIDE?] ELSE PR [HOW LONG IS THE STEP?]MAKE “ANS RLIF: CHOICE = FIRST [S] THEN REPEAT 4 [FD FIRST: ANS RT 90] ELSE REPEAT 360 [FD FIRST: ANS RT 1]END