start translating inline code to Ludus
This commit is contained in:
parent
9890a6f0c2
commit
3a7171b2e3
183
ch_1_intro.md
183
ch_1_intro.md
|
@ -185,12 +185,12 @@ 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.
|
||||
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`.
|
||||
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.
|
||||
|
||||
|
@ -199,7 +199,7 @@ Let's draw a simple 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).
|
||||
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.
|
||||
|
@ -227,9 +227,9 @@ And here is what you will see.
|
|||
|
||||
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.
|
||||
The command `forward! (50); right! (0.25)` 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.
|
||||
Review the `repeat` command; it is exactly what we need here.
|
||||
Try it.
|
||||
|
||||
```
|
||||
|
@ -239,7 +239,7 @@ repeat 4 {
|
|||
}
|
||||
```
|
||||
|
||||
Notice that the line `repeat 4 { forward! (50); right! (0.25) }` 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.
|
||||
Notice that the line `repeat 4 { forward! (50); right! (0.25) }` 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.
|
||||
|
||||
|
@ -249,7 +249,7 @@ Wouldn't it be convenient to be able to "tell" Logo your definition of a square
|
|||
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`.
|
||||
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.
|
||||
|
||||
|
@ -266,14 +266,14 @@ fn box50! () -> {
|
|||
}
|
||||
```
|
||||
|
||||
Logo will add `BOX50` to all its other commands.
|
||||
Each time you type `BOX50`, the turtle will draw a square of size 50.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
|
||||
|
@ -299,23 +299,23 @@ Is one image more pleasing than the other? Why?
|
|||
|
||||
### 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.
|
||||
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.
|
||||
After all, Logo itself doesn't have a different `forward!` 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.
|
||||
There is not a `forward!-10` command for drawing lines of length 10 and a `forward!-43` command for drawing them 43 units long.
|
||||
Logo has a single `forward!` command.
|
||||
Whenever `forward!` is used, an argument must be used in conjunction with it: the form is `forward!` argument.
|
||||
A single argument must be typed just after `forward!`.
|
||||
For example, one could type: `forward! (10)` or `forward! (43)`.
|
||||
The value of the argument "tells" `forward!` 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.
|
||||
`forward! (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.
|
||||
Let's _generalize_ `box50!` in terms of box size as `forward!` is _general_ in terms of line length.
|
||||
|
||||
### Adding an argument to a procedure
|
||||
Define a new box procedure that has a size argument.
|
||||
|
@ -334,7 +334,7 @@ fn box! (edge) -> {
|
|||
```
|
||||
|
||||
### Putting a demonsuation procedure together
|
||||
I am sure that by this time you have already designed some interesting patterns with various `BOX` procedures.
|
||||
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.
|
||||
|
||||
|
@ -355,7 +355,7 @@ Here is an example of such a demonstration procedure:
|
|||
```
|
||||
& A demonstration procedure to show off a design
|
||||
& produced from multiple boxes of different sizes.
|
||||
fn demo () -> {
|
||||
fn demo! () -> {
|
||||
repeat 4 {
|
||||
box! (100)
|
||||
box! (98)
|
||||
|
@ -369,7 +369,7 @@ fn demo () -> {
|
|||
}
|
||||
```
|
||||
|
||||
To see the pattern defined by `DEMO`, type it:
|
||||
To see the pattern defined by `demo!`, type it:
|
||||
|
||||
{{Figure 4: Differently sized boxes. Top of p. 15.}}
|
||||
|
||||
|
@ -414,12 +414,12 @@ To generalize a procedure is to stretch your thinking about what it does; and th
|
|||
Pin that phrase over your computer screen.
|
||||
|
||||
### Generalizing a procedure with arguments
|
||||
Let's go back to that `BOX` procedure.
|
||||
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.
|
||||
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`.
|
||||
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!`.
|
||||
|
||||
```
|
||||
fn box! (edge) -> {
|
||||
|
@ -430,10 +430,10 @@ fn box! (edge) -> {
|
|||
}
|
||||
```
|
||||
|
||||
You need to add a second argument `:N`.
|
||||
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?
|
||||
We can replace the `repeat 4` with `repeat n`.
|
||||
`forward! (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.
|
||||
|
@ -441,12 +441,12 @@ 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`.
|
||||
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:
|
||||
You are ready to write the new procedure `ngon!`:
|
||||
|
||||
```
|
||||
fn ngon! (n, edge) -> {
|
||||
|
@ -458,20 +458,20 @@ fn ngon! (n, edge) -> {
|
|||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
|
||||
### Making the simple more complete
|
||||
What next?
|
||||
How can we make these simple polygons more interesting?
|
||||
Maybe we can add another polygon characteristic to `NGON`.
|
||||
Maybe we can add another polygon characteristic to `ngon!`.
|
||||
|
||||
Sometime in your life you were probably given an exercise like the following.
|
||||
"Cut out some different sized squares from a sheet of colored paper and think about placing the squares on a large piece of white paper.
|
||||
|
@ -484,7 +484,7 @@ Each design used the same squares.
|
|||
What made them different?
|
||||
Their placement.
|
||||
|
||||
Make `NGON` draw a bunch of `NGON`s and put them on the screen according to some placement rule.
|
||||
Make `ngon!` draw a bunch of `ngon`s and put them on the screen according to some placement rule.
|
||||
Take out your notebook and doodle.
|
||||
Here are some results from my doodling.
|
||||
Your approach will be different.
|
||||
|
@ -492,21 +492,21 @@ I'll explain mine, and I'll expect that your plans will go into your notebook.
|
|||
|
||||
Sketches of spinning polygons that grow or shrink as they spin
|
||||
|
||||
{{Figure 6: Sketches of `BOX`es of different spins and sizes. Bottom of p. 19.}}
|
||||
{{Figure 6: Sketches of `box`es of different spins and sizes. Bottom of p. 19.}}
|
||||
|
||||
### Word description of sketched ideas
|
||||
"I want Logo to draw a series of polygons rotating around a common point, and I want each successive polygon to get bigger, or maybe get smaller.
|
||||
|
||||
"I don't know what angle to turn between one polygon and the next, so I'll include an argument called `:ANGLE` that I can vary, to see what happens.
|
||||
"I don't know what angle to turn between one polygon and the next, so I'll include an argument called `angle` that I can vary, to see what happens.
|
||||
|
||||
"I don't know how big the growth should be between one polygon and the next, so I'll define another argument called `:GROWTH`.
|
||||
I'll play with different values of `:GROWTH` to seewhat looks best.
|
||||
"I don't know how big the growth should be between one polygon and the next, so I'll define another argument called `growth`.
|
||||
I'll play with different values of `growth` to seewhat looks best.
|
||||
|
||||
"How do I make `:GROWTH` work?
|
||||
"How do I make `growth` work?
|
||||
Growth can be of two sorts: growth by a constant amount, or growth by a constant percentage.
|
||||
I'll try the latter.
|
||||
That means that if I want polygons to grow by 10%, I define `:GROWTH` to be 1.10.
|
||||
For a 90% shrinkage I would use `:GROWTH`=.9."
|
||||
That means that if I want polygons to grow by 10%, I define `growth` to be 1.10.
|
||||
For a 90% shrinkage I would use `growth`=.9."
|
||||
|
||||
### A procedure to spin polygons
|
||||
```
|
||||
|
@ -520,13 +520,13 @@ fn spingon! (n, edge, angle, growth) -> {
|
|||
|
||||
What is new here?
|
||||
First, there are more arguments than you have seen before.
|
||||
Every time you use `SPINGON`, you must remember to type four numbers after it.
|
||||
Second, this procedure is recursive: the last line in the `SPINGON` procedure asks that `SPINGON` be done again, but with some arguments changed.
|
||||
For example, `(:EDGE)` becomes `(:EDGE*:GROWTH)` the first time recursion is called; and then `(:EDGE*:GROWTH)` becomes `(:EDGE*:GROWTH)*:GROWTH` the
|
||||
Every time you use `spingon`, you must remember to type four numbers after it.
|
||||
Second, this procedure is recursive: the last line in the `spingon` procedure asks that `spingon` be done again, but with some arguments changed.
|
||||
For example, `(edge)` becomes `mult (edge, growth)` the first time recursion is called; and then `mult (edge, growth)` becomes `mult (mult (edge, growth), growth)` the
|
||||
second time recursion is called.
|
||||
A recursive procedure is a procedure that uses itself as one of its parts.
|
||||
|
||||
Will `SPINGON` ever stop? Try it out.
|
||||
Will `spingon!` ever stop? Try it out.
|
||||
|
||||
### Some spingons
|
||||
```
|
||||
|
@ -547,18 +547,18 @@ spingon! (40, 120, 0, 0.25, 19)
|
|||
|
||||
### Stopping recursive procedures
|
||||
One last procedural writing point to review.
|
||||
Having put `SPINGON` into motion, how do you make it stop at a stage of your choosing?
|
||||
Having put `spingon!` into motion, how do you make it stop at a stage of your choosing?
|
||||
You need to have a way of telling it how to stop.
|
||||
That's another characteristic to include as an argument.
|
||||
Look at the following modification to `SPINGON`.
|
||||
Look at the following modification to `spingon!`.
|
||||
Review the conditional commands in Logo.
|
||||
`IF... [something]` is such a conditional.
|
||||
Using the `IF` phrase, everything becomes very tidy.
|
||||
`if ::something:: then ::something:: else ::something::` is such a conditional.
|
||||
Using the `if` form, everything becomes very tidy.
|
||||
|
||||
```
|
||||
fn spingon! (n, edge, angle, growth, times) -> {
|
||||
& Note the new argument above.
|
||||
if lt? (times, 1) then :stop
|
||||
if lt? (times, 1) then :ok
|
||||
& This is the conditional stopper.
|
||||
else {
|
||||
ngon! (n, edge)
|
||||
|
@ -583,7 +583,7 @@ 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 "`;`".
|
||||
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.
|
||||
|
||||
|
@ -596,7 +596,7 @@ Notice the use of comments, too.
|
|||
```
|
||||
fn spingon! (n, edge, angle, growth, times) -> {
|
||||
& Note the new argument above.
|
||||
if lt? (times, 1) then :stop
|
||||
if lt? (times, 1) then :ok
|
||||
& This is the conditional stopper.
|
||||
else {
|
||||
ngon! (n, edge)
|
||||
|
@ -635,8 +635,8 @@ 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_.
|
||||
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.
|
||||
|
@ -644,11 +644,11 @@ Seethe diagram below.
|
|||
|
||||
{{Figure 9: Polygons inscribed in dotted circles. Bottom of p. 24}}
|
||||
|
||||
Call the revised procedure `CNGON` for "**c**entered **NGON**."
|
||||
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.
|
||||
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:
|
||||
|
||||
```
|
||||
|
@ -656,7 +656,7 @@ cngon! (n, rad)
|
|||
```
|
||||
|
||||
Second, imagine yourself as the turtle.
|
||||
How would you walk through the design that `CNGON` must make?
|
||||
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.
|
||||
|
@ -670,7 +670,7 @@ You, as the turtle, begin your journey from position (1), the center of the prop
|
|||
You are facing straight up.
|
||||
|
||||
Pick up your pen and move forward by the amount of the polygon's radius.
|
||||
This is `:RAD`.
|
||||
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).
|
||||
|
@ -691,25 +691,25 @@ 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`.
|
||||
You can use the procedure `ngon!`.
|
||||
But what arguments will you use?
|
||||
It needs some values for `:N` and `:EDGE`.
|
||||
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`.
|
||||
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)`.
|
||||
Now you can draw an `ngon! (n, edge)`.
|
||||
|
||||
You began the `NGON` from position (4).
|
||||
You began the `ngon` from position (4).
|
||||
You will end at the same place.
|
||||
|
||||
Diagram C: **Getting ready to return to the center**.
|
||||
|
@ -719,7 +719,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.
|
||||
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)
|
||||
|
@ -749,7 +749,7 @@ We might as well use this opportunity to review all the bits and pieces of polyg
|
|||
### 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.}}
|
||||
{{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.
|
||||
|
@ -758,7 +758,7 @@ In preparation for these two acts, let's look at all the angles associated with
|
|||
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`.
|
||||
The external angle is the turning angle used in `ngon!`.
|
||||
What about the internal angles, labeled b.
|
||||
We need some work here:
|
||||
|
||||
|
@ -793,8 +793,8 @@ 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`:
|
||||
### Installing the necessary geometry into `cngon!`
|
||||
Here's how far we have gotten with `cngon!`:
|
||||
|
||||
```
|
||||
fn cngon! (n, rad) -> {
|
||||
|
@ -811,7 +811,7 @@ fn cngon! (n, rad) -> {
|
|||
```
|
||||
|
||||
Now we can replace `(angle)` and `(edge)` with the needed expressions.
|
||||
Here is the finished `CNGON`:
|
||||
Here is the finished `cngon`:
|
||||
|
||||
```
|
||||
fn cngon! (n, rad) -> {
|
||||
|
@ -831,11 +831,11 @@ fn cngon! (n, rad) -> {
|
|||
```
|
||||
|
||||
### Lessons and tips
|
||||
When solving visual problems, like this `CNGON` thing, try to break the single big problem down into several smaller problems.
|
||||
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.
|
||||
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.
|
||||
|
||||
|
@ -849,23 +849,23 @@ 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`.
|
||||
Combine the ideas of `spingon!` with your newly constructed `cngon!`.
|
||||
|
||||
### Exercise 1.4
|
||||
Design a fancier `CNGON` that fills up a polygon with textures.
|
||||
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.}}
|
||||
{{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`.
|
||||
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.
|
||||
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.
|
||||
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?
|
||||
|
||||
|
@ -895,6 +895,7 @@ research.
|
|||
* This we do not need here:
|
||||
- Appeals to a manual
|
||||
- The `-` character to continue a line
|
||||
- The discussion of x-y coordinates
|
||||
* Things we do need that are absent (in no particular order):
|
||||
- `let` bindings
|
||||
- M-expression math
|
||||
|
|
Loading…
Reference in New Issue
Block a user