Anda di halaman 1dari 8

Chapter 11

Some Geometry: Triangles


The turtle can draw different triangle shapes. The triangle we discuss below is like a square in that all its sides are equal and all its angles are equal. In this example, the turtle will take 30 steps for ward, the same amount it took in s q u a r e .

>

FD 3 0

Equiangular Triangle

Now comes the big decision. How many degrees does the turtle have to turn to draw this triangle? In school we learned that equiangular triangles have 60 degree angles. Look what happens when the turtle turns 60 degrees.

RT 6 0 FD 3 0 RT 6 0

Interesting, but not a triangle! But we might as well finish it off.


g f S |

FD 3 0 RT 6 0

FD 3 0 RT 6 0

73

FD 3 0 RT 6 0 FD 3 0 RT 6 0

The figure is a hexagon; it has 6 rather than 3 sides. To make a triangle the turtle needs to turn 120 degrees at each corner. Why 120 and not 60? The answer is simple. When the turtle starts its triangle trip, it must turn 360 degrees (a complete circle) before it returns to its starting state. It walks along an edge of the trian gle of the triangle. The turtle does this 3 times. (3 times 120 is 360; 6 times 60 is 360.) When the tur tle draws a square it turns four times instead of three; 4 times 90 is 360! Now we can finish drawing the triangle.

CS FD 3 0 RT 1 2 0 FD 3 0

P*

J>

>

RT FD RT

120 30 120

74

Now you can define the word use the editor to do this.
EDI T "TRI ANGLE

t r ia n g l e

Lets

and now type


REPEAT END 3 [FD 30 RT 120]

Play with this procedure a bit. For example


i>

REPEAT REPEAT REPEAT

3 [ T R I A N G L E RT 1 2 0 ] 6 [ T R I A N G L E RT 6 0 ] 1 0 0 [ T R I A N G L E RT 3 0 ]

T R IA N G L E

In this last example the turtle retraces its path many times. You can always stop the turtle by pressing c t r l - g . You might want to figure out how many times the turtle needs to repeat a set of commands. For ex ample if the turtle turns 30 degrees each round, it has to repeat the set of commands 360/30 or 12 times. Logo can do arithmetic and so can divide 360 by 30 for you.
REPEAT 360/30 [TRIANGLE RT 3 0 ]
r ia n g l e

R E P E A T 3 [T R IA N G LE RT 120]

Here are some designs made by using t


R E P E A T 6 [T R IA N G LE RT 60]

R E P E A T 360/30 [T R IA N G LE RT 30]

( Lets make the turtle draw t e n t . Just running t r i a n g l e is not enough. The t e n t will be tipped.
CS TRIANGLE

Turn the turtle r t 90 and run time the tent is upside down.
I >

t r ia n g l e

This

CS RT 9 0 TRIANGLE

Remember when we made t r i a n g l e , the inside angle was 60 degrees. If we now turn the turtle r t 90 and then l t 60 the turtle is set up for drawing a tent. Of course, we could just turn the turtle r t 30.
CS RT 3 0 TRIANGLE

The procedure, then, is:

TO T E N T RT 3 0 TRIANGLE END
TENT

into TREE Now you can use

t e n t

to help with

t r e e

A
cs
TENT RT 6 0 FD 1 5

76

RT 9 0 FD 15 RT 1 8 0

Now define t r e e . You could then make three or four trees appear on the screen. For example,

RT 9 0 PU FD 3 0

m
LT 90 PD TREE

It is a good programming habit to put the setup instructions in a separate procedure, s e t t r e e will set up the turtle for drawing a new tree on the screen.
TO S E T T R E E RT 9 0 PU FD 3 0 LT 9 0 PD END

We can then use t r e e and s e t t r e e repeatedly.


REPEAT 3 [TREE SETTREE]

If you want to change the distance between trees, then edit s e t t r e e and increase the amount the turtle goes f o r w a r d . Turtle Makes a House You have taught the turtle to make a square and a triangle. Now put them together to make a house.
SQUARE FD 3 0 TRIANGLE

You put them together but the turtle didnt draw a house. There is a bug. The fix is simple. We should use t e n t instead of t r i a n g l e .
SQUARE FD 3 0 TENT

Anda mungkin juga menyukai