The Connected Perimeter
It is now time to consider some more attractive examples to illustrate how, even with only a beginner’s knowledge of computer graphics, it is still possible to draw aesthetically pleasing patterns.
This was fun, and frustrating. Here are my thoughts about working on Exercise 1.8 in (Angell and Griffith, p.17). Get the above file at PlotterFiles.
The objective is to connect all the N points around the perimeter of a circle. The book has a nice listing of the program that draws the figure. And then points out that “if you are using a pen plotter then [the] listing … is not a very efficient way of drawing the pattern.” The next problem (1.9) describes a method referencing the Fibonocci sequence as a way of connecting the points around the perimeter of a square.
Well, I chased that for a while and it really seems to have been a red herring. Or too clever for me. Although I’m really not sure how it connects all the points on a circle when the sequence skips a larger and larger group of numbers as it goes on.
It also distracted me from the relatively simple modification to the listing needed to greatly shorten the trajectory of the pen in the plotter. Here is my pseudo-code of my solution.
You can see the output of the book’s listing, for N=30, in the first tweet (on HP paper). The paper is excellent printer paper, but not up to the task of being hit with a pen in the same place 30 times. It gets pretty roughed up.
I’ll note also that using this algorithm and stopping early has some nice potential for other shapes.
There was a 'Forbidden' error fetching URL: 'https://twitter.com/pentronik/status/1300198873739091968'
The second tweet has the results of my code (based on the pseudo-code above). It is on the back of some Strathmore 300 series Bristol. It handles it better, and also there is a lot less pick up and put down of the pen. But still, the surface is not perfect. It is the edge points that suffer the most, the central point which also is crossed 30 times isn’t so bad looking.
I would have to say my favorite bits of this are around the central point, and the “eggs” fourth ring from the center. Overall, I quite like it, it’s nice that such a pleasing thing is “easily” accessible. Really looking forward to learning some more things from this book.
Improvements
While my solution is quite a bit shorter in travel distance than the original listing, I don’t think it quite makes it to the full 50% reduction. I’ll update with some measurements when I get a chance. I have identified some some further improvements that could be made, if necessary, at a later date.
- In my implementation, there are unnecessary pen up/down steps. This is the pen moving to the start point. It’s already at the start point. I am too pig-headed to do the simple thing and check that the x,y location is at the start point. I would rather check it by indices or something else, and ran out of steam to figure that out this afternoon.
- Probably fairly easy is fact that for the directly across points, it still does travel all the way back across the circle, and the over one point. I really wanted it to go to the next point and draw the line back. Why are even numbers so hard?
- The hardest one. There are unnecessary moves back to the start point. For the circle, at least, the figure is rotationally symmetric. The turtle doesn’t need to move back to the start point. Instead it could use that rotational symmetry to advantage and pick up one of the other jumps. The difficulty with this is the necessary bookkeeping to ensure that all points are visited for all jumps.
It is not clear that all these features are necessary or will even work if I want to generalize to perimeters of other convex polygons. And draw points along the perimeter of the polygon not equal to or even with the number of vertices of the polygon, and not overdraw the sides of the polygon.
References
-
Angell, I.O. and Griffith, G., High-resolution Computer Graphics Using FORTRAN 77, 1987.
There is lots of good stuff in here. @pentronik
More Details