Loading...
Menu

Coding in Logo

p<>{color:#000;}.

Coding in Logo

Published by Camboard at Shakespir.

Camboard Technology

Cambridge England

www.camboard.com

Age range 7+

Coding in Logo is a book designed to help children learn about Logo and use this popular language to draw basic shapes and learn about coding.

Coding in Logo will prove useful for guiding the pupil through drawing simple lines and basic shapes.

Coding in Logo covers the basic Logo style commands and also includes sections on procedures, variables and mathematical operators. Coding in Logo guides the pupil through drawing shapes with the screen turtle.

Coding in Logo uses VR Logo for all logo coding.

Copyright © 2016 Camboard Technology

ALL RIGHTS RESERVED. No part of this eBook may be reproduced, duplicated, given away, transmitted or resold in any form without written prior permission from the publisher.

Limit of Liability and Disclaimer of Warranty: The publisher has used its best efforts in preparing this book, and the information provided herein is provided “as is.” Camboard Technology makes no representation or warranties with respect to the accuracy or completeness of the contents of this e-book and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose and shall in no event be liable for any loss of profit or any other commercial damage, including but not limited to special, incidental, consequential, or other damages.

Trademarks: This e-book identifies product names and services known to be trademarks, registered trademarks, or service marks of their respective holders. They are used throughout this e-book in an editorial fashion only. In addition, terms suspected of being trademarks, registered trademarks, or service marks have been appropriately capitalized, although Camboard Technology cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark, registered trademark, or service mark. Camboard Technology is not associated with any product or vendor mentioned in this book.

All trademarks acknowledged

1.Introduction

2.Moving forwards

3.Turning right and left

4.Drawing a square

5.Pen colors

6.Penup

7.Draw a letter

8.Draw a hexagon

9.Draw a rectangle

10.Draw a triangle

11.Creating a procedure

12.Using variables

13.Drawing patterns

14.Recursion

15.Mathematical operators

16.IF command

  • 1.Introduction*

Logo is a popular computer language invented in the USA, and popularised by Seymour Papert. Logo is used to introduce the basics of programming and control of a screen turtle.

This book is based on VR Logo a 3D based Logo program.

The program is produced by Camboard Technology.

www.camboard.com

VR Logo is a flexible logo graphics program that introduces children to one of the most popular computer programming languages. VR Logo combines turtle graphics with a simplified version of Logo.

Simple commands instruct the on-screen turtle where to move.

VR Logo uses 3D virtual reality graphics. This enables a more realistic view of the turtle and graphics. VR Logo uses Direct X technology this means graphics will look different to older style 2D logo programs.

Logo is a computer language which when used with a screen turtle will direct the turtle around the screen and draw nearly any shape or pattern we want.

The turtle sits on a base in the draw window. Clicking on the window with the left hand mouse button and holding it down allows the viewing angle to be changed. The turtle faces us.

All commands are based on the turtles’ viewpoint.

Commands are typed into the Commands window. Each time you enter a command press the return key or click on the Run Command icon.

The Draw window is where the turtle resides and all drawing takes place in this window. The turtle is situated on a semi transparent base.

Drawing takes place over the base. This base can be hidden by selecting Show Base from the Options menu.

Drawing can take place outside of the base. By clicking over the window with the left mouse button and holding it down, the base can be rotated and flipped over.

Drawings can then be seen from underneath.

The arrow keys on your keyboard enable the base to move up or down, left or right.

 

2. Moving forwards

Logo uses special command words like FORWARD BACK.

These are entered into the white commands white. All command words are shown in capital letters.

The screen turtle is always in the Draw window and this is where our drawings will appear. Underneath our turtle is an imaginary pen, which draws as the turtle moves.

The most basic Logo commands are FORWARD and BACK.

These make the turtle move forward or backward on the screen.

The computer will need to know how much to move the turtle, so after

the FORWARD or BACK commands we type in a number which moves the turtle.

 

Type in FORWARD 10 and press the return key.

The turtle will move towards us drawing a line.

Now type in: -

 

FORWARD 30

 

The line is even longer.

 

Moving backwards

 

The BACK command moves the turtle, as you might have guessed backwards!

This command also has a number after it.

 

Type in: -

 

BACK 40

 

The turtle moves back.

 

3.Turning right and left

Other common Logo commands are RIGHT and LEFT.

These commands also need a number after them. This time the number informs the turtle how many degrees to turn by.

We can make the turtle turn from 1 to 360 degrees.

 

Type in: -

 

RIGHT 90

 

The turtle turns to the right by 90 degrees.

 

Type in: -

 

LEFT 90

 

The turtle turns to the left by 90 degrees.

 

Type in: -

 

RIGHT 360

 

The turtle has not moved from its original position, as there are 360 degrees in a complete revolution.

 

Type in: -

 

RIGHT 90

FORWARD 20

 

The turtle draws a horizontal line across the screen.

 

4.Drawing a square

Type these commands in to draw a square: -

 

FORWARD 10

RIGHT 90

FORWARD 10

RIGHT 90

FORWARD 10

RIGHT 90

FORWARD 10

RIGHT 90

We have used quite a few lines of commands to draw a square, but by using the REPEAT command we can shorten this.

Type in: -

REPEAT 4

FORWARD 10

RIGHT 90

END REPEAT

The square will be drawn again.

5.Pen colors

The turtle can use different pen colors.

This will make our drawings more attractive.

To change the pen color we type in SETPENCOLOR followed by a number between 0 and 15.

 

Now Type in: -

 

SETPENCOLOR 12

FORWARD 10

 

 

The line color is now light red.

 

 

Try typing in this: -

 

SETPENCOLOR 12

FORWARD 10

SETPENCOLOR 9

FORWARD 10

SETPENCOLOR 0

 

 

 

This new line carries on from where the other finished but is in a different color (light blue).

With Logo you may change the color as often as you like.

 

 

 

 

 

 

 

 

 

6.Penup

Select the Program option from the Reset menu. Click on Yes

There are occasions when we want to move the turtle without drawing a line

We need to bring the turtles imaginary pen up so it does not draw.

The PENUP command will do this.

 

Type this in: -

 

PENUP

FORWARD 10

 

The turtle moves forward but does not draw a line.

 

 

 

 

Now type in: -

 

PENDOWN

FORWARD 10

 

 

 

 

This time a line is drawn. The PENUP command is useful for moving the turtle around the screen without drawing a line.

If you need to remove the lines you have already drawn, use the CLEAN command.

 

 

 

 

 

 

 

 

 

7.Draw a letter

Select the Program option from the Reset menu.

Click on Yes

This program draws a letter from the alphabet.

 

LEFT 90

FORWARD 10

RIGHT 90

FORWARD 16

 

 

 

 

 

 

 

8.Draw a hexagon

Select the Program option from the Reset menu. Click on Yes

With the turtle and a few simple commands we can draw any shape we like.

Let’s draw a hexagon!

 

Type in the following: -

 

REPEAT 6

FORWARD 10

RIGHT 60

END REPEAT

 

 

 

 

 

 

 

 

 

 

 

9.Draw a rectangle

Select the Program option from the Reset menu. Click on Yes

We can use the REPEAT command to draw a rectangle, but we need to use this

command in a different way than before.

 

Type in the following: -

 

REPEAT 2

FORWARD 10

RIGHT 90

FORWARD 20

RIGHT 90

END REPEAT

 

This has drawn a rectangle.

 

 

 

 

10.Draw a triangle

Select the Program option from the Reset menu. Click on Yes

The triangle is a shape we can easily draw using the REPEAT command.

 

Type in the following: -

 

LEFT 90

REPEAT 3

RIGHT 120

FORWARD 10

END REPEAT

 

If we had not typed in LEFT 90 the triangle would appear lop-sided.

 

 

 

 

11.Creating a procedure

Select the Program option from the Reset menu. Click on Yes

When we need to draw another triangle, all these commands need to be typed back into the computer.

However by creating a procedure for these commands and naming the procedure triangle, we just need to type in GO triangle.

 

How do we do this?

 

Open the procedures window and type in the following procedure: -

 

PROC triangle

REPEAT 3

RIGHT 120

FORWARD 10

END REPEAT

END PROC

 

In the commands window type:

 

LEFT 90

GO triangle

 

 

 

 

 

 

 

 

The problem now with our triangle is that we cannot change the length of the sides, because the length is already set in the procedure.

 

How can we change this length?

One way would be to directly change the number in the procedure all the time, but this would be time consuming.

A far better way is to use variables. These are names, which can be used to represent a number.

 

 

 

12.Using variables

Select the Program option from the Reset menu. Click on Yes

Type in the following procedure: -

 

PROC triangle

REPEAT 3

RIGHT 120

FORWARD :size

END REPEAT

END PROC

 

In the commands window type:

 

= 10

LEFT 90

GO triangle

 

 

 

 

 

Notice this time we have not put a number after the FORWARD command, Instead we have used a variable called size the name of the variable is not important.

 

Variables like procedures can be called nearly anything you like in Logo as long as they do not use the same words as commands. It is normal to type variables in lower case letters instead of capital letters. We can make the turtle draw multiple size triangles.

 

 

 

 

 

Select the Program option from the Reset menu. Click on Yes

 

Type in the following procedure: -

 

PROC triangle

SUB REPEAT 3

RIGHT 120

FORWARD :size

SUB END REPEAT

END PROC

In the commands window type:

= 10

LEFT 90

REPEAT 4

GO triangle

= :size + 5

END REPEAT

 

Notice the size variable is increased by 5 each time. This enables the turtle to draw larger triangles.

Try altering the REPEAT number and see what happens. This is one way of making interesting patterns with logo.

 

 

13.Drawing patterns

Select the Program option from the Reset menu.

Click on Yes.

Type in this procedure:

PROC drawsquare

SUB REPEAT 4

FORWARD 10

RIGHT 90

SUB END REPEAT

END PROC

In the commands window type:

REPEAT 36

GO drawsquare

RIGHT 10

END REPEAT

 

14.Recursion

By using recursion we can draw some interesting patterns. Recursion is where the procedure in use calls itself over and over again. This program uses a variable called len which increases by 1 each time the procedure is called.

 

Type in this procedure:

 

PROC draw

FORWARD :len

= :len + 1

RIGHT 45

GO draw

END PROC

 

In the commands window type:

 

= 1

GO draw

Click on the Stop procedure icon to finish drawing.

 

 

 

15.Mathematical operators

Logo like most computer languages uses special symbols to represent certain

mathematical operations.

 

+ This is used for addition.

- The minus symbol, also known as subtract.

  • This is used to multiply a number.

/ The divide symbol.

= Assign a number to a variable.

 

We can use these symbols in the following way.

Assigning a number to a variable.

:b = 30 (let b equal 30) the variable b stores the number 30.

Add two numbers together.

:b = :b + 30 Adds the number contained in b to the number after the + symbol.

Stores the result in b, replacing the previous number held by the variable b.

Subtract from a variable.

:b = :b – 30 Subtracts the number contained in b to the number after the – symbol.

Stores the result in b, replacing the previous number held by the variable b.

Multiply the contents of a variable.

:b = :b * 10 The number in variable b is multiplied by the number after the * symbol.

The result is stored in b, replacing the previous number held by the variable b.

Divide the contents of a variable.

:b = :b / 10

The number in variable b is divided by the number after the / symbol. The result

is stored in b, replacing the previous number held by the variable b.

 

 

 

 

 

 

16.IF command

The IF command makes use of these operators

> Greater than symbol.

< Less than symbol

= Equals symbol

 

We can use the IF command in the following way:

:c = 5 Let the variable c store the number 5

IF :c > 2 THEN If the number held in variable c is more than 2

:c = :c + 5 add 5 to the number in variable c and store the result

END IF in variable c.

 

:c = 5 Let the variable c store the number 5

IF :c < 2 THEN If the number held in variable c is less than 2

:c = :c – 5 subtract 5 from the number in variable c and store the

END IF result in variable c.

 

We can use these examples to move the turtle around the screen.

Let’s try some of the examples.

 

:c = 5

IF :c > 2 THEN

:c = :c + 5

FORWARD :c

END IF

 

The turtle will move up the screen 10 units.

 

 

 

Now type in again: -

 

IF :c > 2 THEN

:c = :c + 5

FORWARD :c

END IF

 

The turtle will move up the screen 15 units instead of the previous 10 units.

 

VR Logo is published by Camboard Technology.

 

www.camboard.com

 

 

Copyright © 2016 Camboard Technology

 


Coding in Logo

Coding in Logo is a book designed to help children learn about Logo and use this popular language to draw basic shapes and learn about coding. Useful for the Computing curriculum at Key Stage 2 & 3 and Computer Science K12. Coding in Logo will prove useful for guiding the pupil through drawing simple lines and basic shapes. Coding in Logo covers the basic Logo style commands and also includes sections on procedures, variables and mathematical operators. Coding in Logo guides the pupil through drawing shapes with the screen turtle. Coding in Logo uses VR Logo for all logo coding.

  • ISBN: 9781310163210
  • Author: Camboard Technology
  • Published: 2016-01-18 12:40:14
  • Words: 2355
Coding in Logo Coding in Logo