Nesting Shapes

Revision

This program draws an equilateral triangle.
Each side is 40 units.
The Logo turtle turns 120 degrees at each corner.

repeat 3 [forward 40 right 120]

You must be letter perfect when you type this in!
Press RETURN when you have finished.

You can draw a square by using the code:

repeat 4 [forward 100 right 90]

Task 1 Making a Polygon

The external angle of a polygon of n sides is 360/n
You can write a general polygon program as follows:

edit "poly

Now add the text below so that it reads exactly like that in the diagram.

to poly :length :sides
repeat :sides [fd :length rt 360/:sides] end

Now click on the "file" menu and select "save and exit".

Now enter the command

poly 60 6

This draws a hexagon with sides that are 60 pixels long.

You can hide the turtle by typing ht. This stops it appearing in your designs.

At this point you should use the "file" menu in the main window. This will allow you to reload your "poly" program next time you use Logo.

Assignment 1: Make some polygons.

What happens if you make the number of sides very large?

What shape does your polygon increasingly look like?

Task 2 Rotating Polygons

Use your poly code to make a variety of polygons. Then try this:

repeat 20 [poly 60 6 rt 18]

You can use the "bitmap" menu to save your pictures. You could then edit them in paint. They are exported as bmp files. These are huge so you need to convert them to gif files asap if you are going to email them to anyone.

Assignment 2: Make several designs using what you have learned so far and save them into a "paint" poster.

Task 3 Nesting Polygons

You are going to make a new program called nestpoly. This builds on your "poly" program. Type this in to start the editor window.

edit "nestpoly

Now alter the code to look like the code in the box below. Remember to "save and exit" once you have put it in.

The code works by drawing a polygon. The make command then increases the length by 10 pixels. The program loops through this operation n times.

to nestpoly :length :sides :n
repeat :n [poly :length :sides make "length :length + 10]
end

Now if you type the code below in you should get 10 pentagons that gradually increase in size.

nestpoly 10 5 10

If you edit the main line of your nestpoly program to read like this then you can make a set of polygons that get bigger and rotate clockwise.

repeat :n [ poly :length :sides make "length :length + 10 rt 360/:sides]

"save and exit" from the editor before typing:

nestpoly 20 4 4

Task 4 Challenges

Can you work out how these patterns were made. They only use commands that you have already learned and are based on the nestpoly program.