Вы находитесь на странице: 1из 6

m

Chapter 14 Commands with Two Inputs: Polygons and Arcs

K: ; !' wM I * if |l m m

Chapter 14

Commands with Two Inputs: Polygons and Arcs


Just as you can vary the number of steps the tur tle takes, you can also vary how much it turns. In fact, you can get some really beautiful and sur prising designs by varying these two components of the turtles state. The following procedure takes two inputs: one which specifies the number of turtle steps and one which specifies the amount of turn.
TO POLY -.STEP : ANGLE FD : STEP RT : ANGLE POLY : STEP : ANGLE END

Now try it!


POLY 30 90

POLY 30 90

The turtle does not stop because p o l y keeps tell ing it to go forward and turn. To stop p o l y and the turtle press c t r l - g . Logo responds
STOPPED!

You probably will want to clear the screen (cs). Here are some suggestions for exploring p o l y . You will no doubt want to try other inputs, too.
>

POLY 3 0 1 2 0 POLY 3 0 6 0 POLY 3 0 7 2

97

&

POLY POLY POLY

30 144 3 0 40 30 160

is recursive. That is, instead of calling an other procedure to help out, p o l y calls itself. This is a simple example of recursion. We will meet other examples later.
p o ly

Turtle Draws Arcs Many projects require only pieces of circle. In those cases you can use the commands a r c r i g h t ( a r c r ) and a r c l e f t ( a r c l ) . These procedures need 2 inputs: the first input is the radius of the circle from which the arc is taken and the second input is the number of degrees of the arc.

r
ARCR ARCR 30 30 90 90

Bug Box If Logo does not know how to a r c r or a r c l skip the rest of this chapter. Appendix A offers an ex planation of why Logo might not know how to do these procedures. Clear the screen and try some other inputs.

98!

ARCL 4 0 1 2 0 LT 1 2 0 ARCL 4 0 1 2 0

A Fish!
r r & 0

ARCR 4 0 9 0 RT 9 0 ARCR 4 0 9 0 RT 9 0

A Petal! Arcs, Petals, Flowers, Swans


TO PETAL : S I ZE ARCR : S I Z E 9 0 RT 9 0 ARCR : S I Z E 9 0 RT 9 0 END

Try
PETAL REPEAT REPEAT 453 40 8 4 PETAL [PETAL [PETAL 30 40 30 PETAL RT 4 5 30 RT 45] 40 RT !

PETAL

Notice that Logo lines can extend beyond one screen line. Logo marks continuation lines by put ting a ! (exclamation point) in the last character position of the line. The rest of the text flows onto the next screen line. You might want to make a f l o w e r out of one of these designs. Now lets do a s w a n .
99

I!

% >

>
1

i i I I ;

SWAN

U3E-A D

ne c k

BODY

There are really only' 2 (Afferent shapes, mT.*x and nkcit. Vfe can use p r ta l to make ody ar.n
W&A&. to. &a&y H 45 T

M 45 i>!TA4 JSIZE
E-M

1 > ( o

TO m iK iS rz-E: i f 45
A-ffSft i S I Z i

fcf 45

A C - JfZE 90 RH

TO KEAl>

> < o

PETM ; SIZE:

LT 135
E 'D ^ '

!z e i

RT 135

& A , the coiitrolfeg procedure, fe WW


sW ft 64 A
TO SWAM ; S 1Z ! &0&Y ; S I Z '< :: C < : > I z E / 2 HEAD ; S I Z E / 4 M>

100

Вам также может понравиться