> "Chance favors the prepared mind." Louis Pasteur
### Who I hope you are
You might be interested in the studio arts--painting, drawing, sculpture, photography--or in architecture.
You may have had experience in graphic, commercial, or industrial design.
Then again, you might be a liberal arts type with a background in language, literature, music, or science.
Or perhaps you are a professional type educated in the field of business, law, medicine, or theology.
You could be a student or a teacher or neither or both.
You may have spent long hours in art studios and possess an exceptionally rich, visual vocabulary.
Then again, your graphic abilities, both verbal and physical, may be very much on the thin side.
Instead, your vocabulary might be skewed toward logic and mathematical terms because your background is in the sciences, philosophy, law, or mathematics.
You may not be able to describe every phase that Picasso went through, but you enjoy looking at art, and you can differentiate a Picasso from, say, a Pissarro when you see them side by side.
You probably have a favorite artist or a favorite period, and you have paintings or reproductions of them in your own home.
While you may not be able to sketch the Acropolis using 3--point perspective, you do have some idea of what perspective means.
You would be intrigued by the suggestion that, in fact, there are dozens of different ways to illustrate objects in space.
At some time in your past, you must have taken a course in geometry.
(Everybody has taken a course in geometry.
It is one of the few bits of liberal
education that we still share.)
What about trigonometry?
You may have forgotten everything, but you aren't brought to the edge of coronary arrest by hearing the words _geometry_ and _trigonometry_.
Finally, and most important, whatever your curriculum vitae says, and whatever type of intellectual or visual baggage you carry, _I hope that you are excited by looking at things and by thinking about how things look._
This book will show you how to increase this kind of excitement by encouraging you to build a special, visual variety of computer models.
If you are stimulated by this idea, then you are exactly who I hope you are.
### Your computer baggage
This chapter gives a very quick summary of basic Logo.
It is brief, not just because I hope that you already know a little Logo but because I expect that you are willing to use the manual that came with your copy of Logo.
In other words, I expect that you are willing to do some learning about Logo mechanics on your own.
If you have never met Logo before, probably you have been introduced to some other computer language and most likely this other language was BASIC.
(I am saddened to think of you learning BASIC before Logo, and this book will give you the chance to right that terrible wrong.)
If you do know something about one computer language, you should be able to plunge happily into the manual of a second language--Logo.
I will give you some directional help, though, by suggesting what questions you need answered in your manual.
Then it will be up to you to learn the specifics.
I assume, too, that you have played around with personal computers and
know how they "feel." You may like or dislike these machines, but your feelings are based on personal experience.
You are familiar with disks, disk drives, keyboards,and program editors.
### No baggage
If you have had no experience with personal computers, and have never tried to learn a computer language--on your own or in a course--you may find this book rough going.
If, on the other hand, you have access to a teacher, tutor, or friend who is willing to give you help when you ask for it--and if you are patient, curious, and tenacious--I think you should stick around.
### Programming as craft
Learning to program in Logo is very much like learning a craft.
You can read about "doing Logo" as you can read about making furniture, and you can talk to others about doing it as well.
But in order to develop the individual talents and skills do old needed for yourself.
For the newcomer to a craft, a master artisan can certainly be of help.
The old timer can suggest small, beginning projects that are reasonably taxing but not overly intimidating.
And by offering encouragement, he can keep the novice's spirits high.
This chapter is designed to reinitiate you into the excitement of Logo craft; all the exercises within the chapter have been fashioned by an experienced craftsman.
These initial projects should be copied.
All artisans begin learning their craft by copying what others have done.
This is not to deny their creativity but rather to allow for a strengthening of the basic skills that support individual creativity.
Good craftsmanship, of course, requires both skill and creative flair.
For my purposes, skills are as much frames of mind as forms of physical dexterity.
For example, in this chapter I will stress the usefulness of three such skills: first, an ability to break down big problems into smaller problems; second, a willingness to imagine yourself as "walking" shapes into existence; and third, a propensity to tinker with your Logo machinery.
Very soon (starting with the exercises at the end of this chapter, in fact) you will be asked to apply these skills to support your own kind of invention.
Craft is about building things by hand, and that is what you will be doing with Logo.
### Copying and tinkering
Copying computer programs is so widespread that I had better give you my opinion about the usefulness of it all.
In the previous paragraph I said that copying was a good thing at the start of one's apprenticeship.
As you go through this chapter, I hope you will want to try out my procedures.
That's OK.
But if you simply type my procedures into your computer, you will only reproduce what I have done.
And that will bore us both.
The book shows what I have done; it doesn't show what you can do.
My procedures offer you a starting place, so that you don't have to build from zero.
But it is up to you to go beyond that start.
So please do copy the ideas of any procedure that strike your fancy.
But, once you have made those ideas work on the screen, play rough with them.
Give the copied procedure funny and outlandish arguments.
(Very big or very small numbers could be outlandish, but what is a funny argument?)
What happens then?
Does your copied procedure still work?
Can you explain how?
Go on to make a few changes inside the body of the procedure; change some of the commands just a little.
Can you guess what might happen before you experiment on these changes?
Get into the habit of tinkering, just a little.
Whenever you write, or copy, a nice procedure, make a few changes to it so that it does something else.
### Equipment
Your most important piece of equipment is a notebook.
It is far more important than the computer you work on and all the technical manuals at your disposal.
Select a notebook with large, unlined, and bound-in pages.
I want you to keep track of your work in this notebook.
That means everything: the little sketches, word portraits, diagrams, procedure listings, the printed images.
Stick in any magazine and newspaper illustrations that strike your fancy, whenever you find them; don't worry aobut organization.
You will be mixing the good with the less than good, the things that worked well with those that never will.
I suggest that a large format notebook is best.
That means plenty of room for a lot of stuff.
Small notebooks encourage crabbed handwriting and get messy; you will need a lot of space.
Also, unlined paper is better.
Since there is no need to write carefully, lines will get in the way.
If you need graph paper for a careful diagram, glue a piece in.
And, finally, the bound--in pages will not let you reorganize the book.
The notebook may organize you.
Glue.
Rubber cement is the Queen of Glues and the world's best notebook adhesive.
Get a lot of it.
Be careful using this glue, though; it is very flammable.
> Appendix A in Brian Harvey's _Computer Science Logo Style_, volume 1: _Intermediate Programming_ (Cambridge, MA: MIT Press, 1985), gives a nice summary of the syntactic differences between Logos. It gives no help with the differences in graphics, though.
You may have a different machine and a different Logo.
To make life as easy as possible, and to eliminate the need to talk about dialects, I have tried hard to avoid using those components that vary most between Logos.
The bad news: this is a book about graphics and graphics is the area in which Logos differ most.
So I skirt any graphics razzle-dazzle that might work in one Logo and not in another.
I don't use funny pen patterns, polygons filled with patterns that look like brick walls or tile roofs, or automatic mirrors that reverse images.
There are no sprites or multiple turtles.
The only colors I use are white, black, and (very occasionally) a reversing pen color.
All the line drawings have been done with a standard, narrow-width pen.
### Caveat emptor
This is a little late for a warning, but here it is anyway: _This is not a bookabout Logo._
You will end up knowing a lot about Logo, and that is no bad thing.
But the goal of the book is to get you to build visual models, and Logo is only a means to that end.
God knows, we could have used Pascal.
But it just so happens that Logo is easier to learn and easier to use than most of the other languages that we could have selected.
Logo notation is neat and tidy; it looks nice on the page and that encourages visual thinking.
But most important, because Logo is so easy to play around with, it won't get in the way.
### Turtles are us
We will concentrate on the graphic parts of Logo.
And that means "turtle graphics."
The intent of Logo's turtle metaphor was to inspire young children to explore shapes.
The turtle is a tiny triangle of light that is moved about the screen via Logo commands.
As the turtle moves, it leaves a trace of light.
Children are encouraged to imagine themselves in the turtle's place and to draw a shape by walking through it, as the turtle would walk through it.
Children have the necessary body knowledge to walk a circle, even though they cannot express their circle drawing rules before walking them.
Walking the turtle around an invisible circle translates the body's knowledge into word commands:
"I'm walking him forward a little bit, now I'll turn him a little, I'm walking him forward a little bit, now I'll turn him a little...
I'll keep doing this until until he's finished.
Yes, that's it; I'm back where I started."
Once said, the words are available to be transformed into Logo commands.
Because adult bodies may be more spatially intuitive than children's, your turtle visualizations can be far more effective than a child's.
There is a problem with adults, though; they aren't used to playing imagination games as adults and must be coaxed into it.
Children are happy to play silly games; adults may be embarrassed to try.
I will be asking you, after all, to imagine yourself as an electronic turtle.
And what would that feel like, I mean physically?
Use your turtle body and walk around a bit.
Don't reject visualization and muscular thinking before you try it.
What was good enough for Uncle Albert should be good enough for you.
Listen to what he said:
"The physical entities which seem to serve as elements in thought are certain signs and more or less clear images which can be 'voluntarily' reproduced and combined... this combinatory play seems to be the essential feature of productive thought.
The above elements are, in my case, of the visual and some of the muscular type."--Albert Einstein
### Turtle space
Turtles live on your computer screen.
Make sure you know the size of yours, since different computer screens have different dimensions.
Screen dimensions are generally stated in vertical (the y-axis direction) and horizontal (the x-axis direction) measurements.
Pinpoint the `x = 0` and `y = 0` point on your screen.
The turtle can be moved about the screen using cartesian x-y coordinates or turtle coordinates.
Cartesian commands send the turtle to a specific xy position on the screen, without regard to the turtle's current position.
Various `SET` commands move the turtle through cartesian space.
Review them.
In the turtle reference system, all commands refer to the turtle's current position, not its final position.
The turtle is moved forward, backward, turned left or right in relation to where it is now.
Review the turtle reference commands: `FD`, `BK`, `PU`, `PD`, `RT``LT`.
In the cartesian system, the destination is the important thing; in the turtle reference system, it's the trip.
### Making shapes
Let's draw a simpel shape using turtle reference commands.
Suppose you would like the turtle to draw a square box located at the center of the screen (usually the origin of the coordinate system).
Here are the steps you would take:
First, you would clear the screen by typing `CG` (clear graphics).
The trutle now sits at 0,0 and faces straight up.
Second, you would think about the commands needed to walk the turtle through the shape.
_Use_ the turtle metaphor.
1. "OK turtle? Go forward 50 steps and turn right by 90 degrees. That completes the left side of the box."
2. "Now, go forward another 50 steps and turn right by 90 degrees. That completes the top of the box."
3. "Go forward yet another 50 steps and turn right again by 90 degrees. That completes the right side of the box."
4. "Go forward another 50 units and turn right 90 degrees. That completes the
bottom edge of the box."
That's it.
The turtle has walked around the four sides of a size 50 box, arriving back to where it started.
These prose commands would translate into Logo as:
1.`FD 50 RT 90`
2.`FD 50 RT 90`
3.`FD 50 RT 90`
4.`FD 50 RT 90`
The third and last step would be to type these commands on the keyboard.
And here is what you will see.
{{Figure 1: A simple box. Top of p. 10.}}
Great.
This series of commands does indeed draw the square you wanted; but wasn't it tedious to type in all that stuff?
The command `FD 50 RT 90` was typed four times.
Surely there is a shorthand method to repeat this line four times without typing four times.
Review the `REPEAT` command; it is exactly what we need here.
Try it.
```
CG
REPEAT 4 [FD 50 RT 90]
```
Notice that the line `REPEAT 4 [FD 50 RT 90]` is a kind of operational definition of what a square is: a square is four sides, four `FD` commands, with each side joined at right angles to the next, the `RT 90` commands.
That's tidy, but it's still a bore to type two lines each time you want a size 50 box on the screen.
After all, you may want to draw 100 boxes.
Wouldn't it be convenient to be able to "tell" Logo your definition of a square and then to give that definition a name?
### Logo procedures group commands under a single name
You can group a series of Logo commands together under a single name by writing a Logo procedure.
The name of the procedure is a shorthand for all commands included in it.
Typing the name of the procedure tells Logo to automatically execute each line of the procedure in turn, just as if you had typed them, one after another, on the keyboard.
You can "tell" Logo your definition of a square by creating a procedure called `SQUARE`.
Logo will "remember" your definition until you either erase it or turn off your computer.
Review the defining and editing procedures in your Logo manual.
### Shapes defined and drawn by procedures
Let's get on with writing the necessary procedure.
Here it is:
```
TO BOX50
REPEAT 4 [FD 50 RT 90]
END
```
Logo will add `BOX50` to all its other commands.
Each time you type `BOX50`, the turtle will draw a square of size 50.
The figure will be drawn at the turtle's current position on the screen.
Unless you move the turtle to a different starting point, each time you type `BOX50`, the square produced will be on top of the previously drawn figure.
So move the turtle around to new positions and draw some more boxes.
But you can certainly be more imaginative than that.
Create an interesting design on the screen using only the `BOX50` procedure and move commands.
If you have a color screen, you might want to investigate the effects of changing the screen's background color and the color of the pen.
Keep track of what you are doing in your notebook so that you can reconstruct your successful designs.
Here is a simple command that wraps boxes around the screen:
```
REPEAT 25 [PD BOX50 PU RT 15 FD 60 LT 15]
```
### Wrapped boxes
Here are two different images produced by that one-liner.
How are they different?
Is one image more pleasing than the other? Why?
{{Figures 2 & 3: Wrapped boxes. Bottom of p. 12.}}
### Generalizing procedures
What about boxes of different sizes?
You could edit the `BOX50` procedure every time you wanted it to draw a different size box.
You could also define many `BOX`-like procedures, each to draw a different size box.
But that doesn't seem very efficient, does it?
After all, Logo itself doesn't have a different `FD` command for every possible length of line that you might wish the turtle to draw.
There is not a `FD-1O` command for drawing lines of length 10 and a `FD-43` command for drawing them 43 units long.
Logo has a single `FD` command.
Whenever `FD` is used, an argument must be used in conjunction with it: the form is `FD` argument.
A single argument must be typed just after `FD`.
For example, one could type: `FD 10` or `FD 43`.
The value of the argument "tells" `FD` how to go about its business of drawing straight lines.
Isn't this convenient?
One command does a variety of things.
`FD argument` draws straight lines of _any_ length.
If we change the value of the argument, the line length changes accordingly.
Let's _generalize_`BOX50` in terms of box size as `FD` is _general_ in terms of line length.
### Adding an argument to a procedure
Define a new box procedure that has a size argument.
The value of the argument will tell the box procedure how to go about its business of drawing boxes.
Changing the value of the argument will change the size of the box.
You can now draw boxes of any size from, say, 1 unit to 5000 units.
Use this example as a "pattern" for incorporating an argument into a procedure.
```
TO BOX :EDGE
REPEAT 4 [FD :EDGE RT 90]
END
```
### Putting a demonsuation procedure together
I am sure that by this time you have already designed some interesting patterns with various `BOX` procedures.
Some of these patterns you probably liked enough to print and glue into your notebook.
Remember to include a few written comments on what you were trying to achieve.
Perhaps you would like to show off your designs.
You could show your pals the images in your notebook.
But seeing an image is not the same as seeing how the image is drawn, the order in which the pieces are visually assembled.
How would you go about demonstrating this?
You could retype all the Logo commands needed for your screen collage.
What else could you do?
Remember that Logo procedures can group a series of commands together under one name.
So let's define a new Logo procedure that will run all the necessary steps to demonstrate your design.
Once defined, you will only have to type the demonstration procedure's name to have your designs redrawn on the screen.
Your demonstration procedure will have no arguments; it will only do one thing: generate a specific design that you want to show to your friends.
If you wish to show off with several designs, you could design specific Logo procedures to reproduce eachdesign.
Here is an example of such a demonstration procedure:
```
TO DEMO
; A demonstration procedure to show off a design
; produced from multiple boxes of different sizes.
REPEAT 4 [BOX 100 BOX 98 BOX 96 BOX 75 BOX 40
BOX 35 BOX 30 RT 90]
END
```
To see the pattern defined by `DEMO`, type it:
{{Figure 4: Differently sized boxes. Top of p. 15.}}
### Funny feelings
Do you have a funny feeling that this isn't enough, that we aren't producing great enough images?
Let's think about this for a while.
Drawing with Logo should not be the same as drawing with a pen or pencil.
What can be sketched quickly by hand is unbearably tedious to sketch with Logo.
You may have tried sketching with Logo by moving the turtle as you would move your sketching hand.
It doesn't satisfy, and it doesn't work.
Logo is a unique medium for visual expression; don't expect it to be like other media.
Visual modeling with Logo is as different from drawing as clay modeling is different from photography.
Our Logo media is a visual modeling media.
We use it best to build models.
Why?
To encourage us to think about shapes.
The drawing is done to encourage thinking.
So don't worry too much (now) about the final image.
Don't worry if your designs aren't amazingly beautiful; don't be concerned if they aren't "arty."
This isn't, after all, a book about computer "art," but it might be useful to think about ART for a minute.
Here is a quote from a computer art type, Harold Cohen from the University of California at San Diego:
"For most people outside of art, probably, art is directed primarily at the production of beautiful objects and interesting images; and who is to argue that a complicated Lissajou figure is less beautiful than an Elsworth Kelly painting or a Jackson Pollock; or that a machine simulation of Mondrian is less interesting than the original it plagiarizes?
To talk of beauty or of interest is to talk of taste, and matters of taste cannot be argued with much profit.
The fact is that art is not, and never has been, concerned primarily with the making of beautiful or interesting patterns.
The real power, the real magic, which remains still in the hands of the elite, rests not in the making of images, but in the conjuring of meaning."
A little professorial, this.
But do you think he has a point?
Go back to your demonstration procedures, the ones that have _no_ arguments so they do only _one_ thing.
A procedure that does only one thing is like a box drawing procedure that draws only one size of box.
One box doesn't encourage much thinking about the nature of boxes, does it?
Can you use your demonstration procedures to explore the nature of a collage that intrigues you?
Play around with the collage demonstration procedure that draws it.
Tinker a bit.
Maybe you could generalize the demonstration procedure by adding an argument.
To generalize a procedure is to stretch your thinking about what it does; and that's our appropriate work, too, because it respects the uniqueness of the Logo art medium.
"It's the tinkering that counts, not the artiness."
Pin that phrase over your computer screen.
### Generalizing a procedure with arguments
Let's go back to that `BOX` procedure.
Can we generalize it so that it draws triangle "boxes" as well as square ones?
While we are at it, let's ask `BOX` to draw boxes with any number of equal sides.
These shapes will be regular polygons with n sides.
Why not call the generalized procedure `NGON` for n-sided polygon?
Look again at the procedure BOX and decide what needs to be changed to turn `BOX` into `NGON`.
```
TO BOX :EDGE
REPEAT4 [FD :EDGE RT 90]
END
```
You need to add a second argument `:N`.
This will tell Logo how many sides to draw.
We can replace the `REPEAT 4` with `REPEAT :N`.
`FD :EDGE` will stay the same, but what about the angle you want the turtle to turn before drawing the next side?
It surely will be different for different sided polygons.
Generally, sketching focuses geometric thinking.
Here are some walking plans that you might issue to the turtle to do NGON.s 7.
{{Figure 5: Triangle, square, pentagon. Middle of p. 17.}}
How can you calculate the angle indicated by the "?" for any n-sided polygon?
Your geometric intuition should tell you that the turtle, after making `:N` turns, will end up facing the same direction in which it started.
The amount of each individual turn will be 360 divided by thenumber of turns,or `360/:N`.
(Now is the time to recall Logo's mathematical capacities.
Review the Logo notation to add, subtract, multiply, and divide.)
You are ready to write the new procedure NGON:
```
TO NGON :N :EDGE
REPEAT :N [FD :EDGE RT 360/:N]
END
```
Try it out.
Notice that when: N becomes large, the drawn figure becomes a circle (almost).
Carry out some clever visual experiments with `NGON`s.
### Some observations
Look back carefully at what we have done so far with procedure writing.
We started with a list of commands that drew a box of a single size.
Next, we grouped these commands into procedures that could draw boxes of several different sizes.
Next, we generalized the `BOX` procedure with an argument so that it could draw boxes of any size.
Finally, we produced a still more general procedure, `NGON`, that can draw any regular, polygonal "box"--triangles, squares, pentagons, hexagons, and so on--of whatever size we wanted.
Before ending this chapter, let me give you a few more items to review from your Logo language manual.
The topic that gives most students the most problems is one of the most boring things to talk about: file maintenance.
So I won't talk about it.
But please review how to save text material as files, how to retrieve material from files, how to erase files, how to catalog files, and how to print files.
Do the same review for storing and retrieving graphics information.
### A note on the procedure presentation style used in this book
I have tried to make the presentation of procedures in this book as readable as
possible.
Here are several of my presentation rules.
First, the _many comments_ rule.
I have included wordy explanations in some of my procedures.
These comments begin with the Logo command "`;`".
There is, of course, no need for you to include thesecomments in your own version of my procedures.
However, it is a good idea for you to put comments in your own procedures.
Second, the _meaningful cluster_ rule.
I often include extra parentheses to group like elements into a cluster.
This is useful, for example, when an argument is composed of a collection of Logo material, but you want to see it as a single cluster of information.
Procedures should be laid out nicely on the page without too much information on anyone line.
Long procedure statements should be divided up between lines to make them more readable.
The special character "`-`" is used to indicate when a single Logo statement has been continued from one line to the next.
Here is an example.
Notice that the Logo material within the [repeat brackets] would have been difficult to read if the long statement had not been divided into several short lines.
```
TO SQUIGGLE :A :B :N
REPEAT :N [ FD :A -
RT 130 -
FD :A -
RT 50 -
BK :B ]
END
```
The symbol "`-`" indicates, of course, that the return key should not be used becausethe Logo statement continues.
Consult your own Logo manual for handling the problem of procedure layout.
### Exercises
There are five exercises to explore before going on to the material of chapter 2.
The first is so important that we will go through it together, step by step.
You can work on the other exercisesby yourself.
#### Exercise 1.1
Make `NGON` more versatile by doing two things to it.
First, improve `NGON` so that it will draw polygons _around a central point_; and second, improve `NGON` so that it can be given an argument that specifies not the length of an edge of the polygon but the _radius of the polygon_.
I've made up the term radius of a polygon.
It is the radius of the smallest circle that just encloses a regular polygon.
The center of this circle is the point around which the polygon is to be drawn.
Seethe diagram below.
{{Figure 9: Polygons inscribed in dotted circles. Bottom of p. 24}}
Call the revised procedure `CNGON` for "**c**entered **NGON**."
Two hints: First, ask yourself what arguments `CNGON` will need.
This is another way to ask yourself what information must be given to `CNGON` so that it can go about its business of drawing centered `NGON`s.
`CNGON` needs only two pieces of information, or two arguments: the number of sides of the polygon to be drawn and the radius of that polygon.
That means that the first line of the new procedure will look like this:
```
CNGON :N :RAD
```
Second, imagine yourself as the turtle.
How would you walk through the design that `CNGON` must make?
Draw a simple diagram to describe such a "turtle walk."
You might want to divide the diagram up into individual scenes.
Later you can translate each scene in words and then into Logo notation.
Here is the first instance where this turtle visualization is really needed.
Let yourself go; talk out loud; get on with it without too much thinking.
You, as the turtle, begin your journey from position (1), the center of the proposed polygon.
You are facing straight up.
Pick up your pen and move forward by the amount of the polygon's radius.
This is `:RAD`.
This puts you in position (2).
You now need to turn right by an amount that is labeled (angle) on the sketch (3).
What will (angle) be related to?
Will (angle) be different for differently shaped polygons, that is, polygons with different numbers of sides?
Yes.
Will (angle) be related to the overall size of polygons?
No.
Don't worry about how to calculate (angle), yet; you can work that out later.
### Turtle walk sketches
{{Figure 10: Turtle walk sketches. p. 26.}}
After turning right by the amount of (angle), you are looking along one of the polygon's edges (4).
Put down the pen in preparation for drawing the polygon.
Diagram B: **Drawing the polygon**.
You are at position (4) and ready to draw an n-sided polygon.
You can use the procedure `NGON`.
But what arguments will you use?
It needs some values for `:N` and `:EDGE`.
Right?
Yes, but wait a minute.
What should the value for `:EDGE` be?
You know the value of `:N`, the number of sides of the polygon.
And you know the value of the new argument, `:RAD`.
What must the polygon's edge dimension be so that, after it is drawn, it has a radius equal to `:RAD`?
In other words, we need to be able to express `:EDGE` in terms of `:N` and `:RAD`.
OK.
We know the problem, what we have to work on, but let's not stop yet.
Label the edge thing that must be calculated (edge).
We will return to it in a minute.
Now you can draw an `NGON :N (edge)`.
You began the `NGON` from position (4).
You will end at the same place.
Diagram C: **Getting ready to return to the center**.
You are at position (6). You must now turn left by the amount of (angle); this is indicated by (7).
This leaves you in position (8), pointing straight up.
Diagram D: **Returning to the center of the polygon**.
Pick up your pen and back down, by an amount equal to `:RAD`, to the polygon's center.
Finally, put your pen down in preparationfor whatevermight comenext.
Note that you, as the turtle, have ended in the sameposition (9) as you began (1).
### A turtle walk transfonned into a Logo procedure (almost)
No more words are necessary.
Here it is.
```
TO CNGON :N :RAD
PU FD :RAD
RT (angle) PD
NGON :N (edge)
LT (angle)
PU BK :RAD PD
END
```
The procedure is sketched.
And we know what we know and what we don't.
The two amounts, (angle) and (edge), are still unknown.
To figure these bits will require a little geometry and trigonometry.
We might as well use this opportunity to review all the bits and pieces of polygons.
### The Geometry of CNGONs
Use the following two diagrams in conjunction with the word and equation descriptions.
{{Figure 11: Geometry of `CNGON`s. Bottom of p. 28.}}
The first problem we face is to find an expression for angle d in terms of n, the number of sides of the polygon.
The second problem is to find an expression for the length of a polygon's edge, e, in terms of its radius, R, and n, the number of sides.
In preparation for these two acts, let's look at all the angles associated with polygons.
The _central angles_, labeled a, are easy.
They are each equal to 360/n.
The _external angles_, labeled c, are also equal to 360/n.
The external angle is the turning angle used in `NGON`.
What about the internal angles, labeled b.
We need some work here:
(1) c = 360/n,
(2) c + b = 180.
Putting these two equations together and solving for b gives
(3) b=180*(n-2)/n.
We are now ready to handle the first problem: Find d in terms of n.
(4) d + b/2 = 180.
Putting (3) and (4) together and solving for d gives
(5) d = 180 - 90*(n-2)/n <---**Firstproblemsolved**.
OK, now look at the second problem: Find e in terms of R and n.
(6) sin (a/2) = (e/2)/R,
(7) a = 360/n.
Putting (7) and (6) togetherand solving for e gives
(8) e = 2\*R\*sin(180/n) <---**Secondproblemsolved**.
Review the following trig functions: sine, cosine, and tangent.
What is ani arctangent?
Draw some diagrams to explain each of these functions.
Glue them on the inside cover of your notebook.
### Installing the necessary geometry into `CNGON`
Here's how far we have gotten with `CNGON`:
```
TO CNGON :N :RAD
PU FD:RAD
RT (angle) PD
NGON :N (edge)
LT (angle)
PU BK :RAD PD
END
```
Now we can replace `(angle)` and `(edge)` with the needed expressions.
Here is the finished `CNGON`:
```
TO CNGON :N :RAD
PU FD :RAD
RT 180 - (90*(:N-2)/:N) PD
NGON :N (2*:RAD*SIN (180/:N))
LT 180 - (90*(:N-2)/:N)
PU BK :RAD PD
END
```
### Lessons and tips
When solving visual problems, like this CNGON thing, try to break the single big problem down into several smaller problems.
Solve each of the small problems in turn, and then plug the little solutions together to form one big solution.
#### Exercise 1.2
Put together one or more DEMO procedures that make imaginative use of the ideas presented and reviewed in this chapter.
Modify every procedure in the chapter.
Make them act more strangely.
You might want to think some more about the exercise, described above, of placing simple shapes on a blank field of paper to depict different feelings of balance or emotions.
A painting by the Russian artist Kasimir Malevich is reproduced below.
What could be more elegant that these eight red rectangles?
(That' s the title, by the way.)
What emotion do you feel when looking at this littel reproduction?
Can you do something similar?
{{Figure 12: Kasimir Malevich, _Eight Red Rectangles_. https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Malevich-Suprematism..jpg/640px-Malevich-Suprematism..jpg. Bottom of p. 31.}}
#### Exercise 1.3
Combine the ideas of `SPINGON` with your newly constructed `CNGON`.
### Exercise 1.4
Design a fancier `CNGON` that fills up a polygon with textures.
Here are a few visual tips for Exercises 1.3 and 1.4:
{{Figure 13: `SPINCNGON`s. Bottom of p. 32.}}
#### Exercise 1.5
Design a Logo procedure that puts polygons on the vertices of other polygons.
Hint: look carefully at the body of `CNGON`.
When does the turtle arrive at a polygon vertex?
Mark the vertex arrival place in the `CNGON` procedure.
You might consider this location as the right spot to install some recursion: when the turtle arrives at any vertex, ask it to do another `CNGON` centered on that vertex.
This recursive drawing will place polygons on the vertices of polygons on the vertices of polygons.
You will need to figure out a way of stopping the recursion machinery, or it will continue forever.
Define a new argument, `:LEVEL`, to keep track of recursion levels.
What about the relative sizes of the polygons?
Should they get bigger or smaller? Can you handle that?
Don't forget the following tricks:
1. Imagine yourself as the turtle.
2. Sketch the design that the turtle must walk through.
3. Describe the turtle walk in words.
4. Divide the walk up into logical sections.
5. Note the bits you know and the bits that will need some further thought and
research.
6. Translate the words into Logo commands.
7. Test it out with realistic and totally outlandish argument values