Classic Computer Magazine Archive COMPUTE! ISSUE 74 / JULY 1986 / PAGE 10

Readers Feedback

The Editors and Readers of COMPUTE!

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

Faster Fractals In Forth

I enjoyed reading Paul Carison's article on fractal graphics for the IBM PC/PCjr (COMPUTE!, March 1986). His explanations were very clear. But it must have been a real trial for him to develop the BASIC version of the "Eight Thousand Dragons" program. We would like to show the beauty of fractals when written with a language that supports recursion. Here is an example of Forth code that does the same thing. It's written for Mach1, our Forth compiler for the Apple Macintosh and Atari ST. The execution time for a fourteenth-degree dragon is only three minutes.

:Drag RECURSIVE { x1 y1 x2 y2 x3 y3 k | x4 y4 x5 y5 }
      PAUSE
      k 0=            (if k=0 just draw and return)
      IF              (else continue breaking lines down)
            k 1 - -> x4
            x1 x2 + 2 / y2 y1 - 2 / - -> x4
            y1 y2 + 2 / x2 x1 - 2 / + -> y4
            x2 x3 + 2 / y3 y2 - 2 / + -> x5
            y2 y3 + 2 / x3 x2 - 2 / - -> y5
            x1 y1 x4 y4 x2 y2 k Drag
            x2 y2 x5 y5 x3 y3 k Drag
      THEN;
:Dragon { iters -- }  ('14 dragon' gives the best results)
      CLS
      100 190 CALL MoveTo    (place pen at beginning)
      100 190 228 62 356 190 iters Drag   (start with initial seed)
Terry Noyes

Although recursive routines (program segments that call themselves) are ordinarily taboo in BASIC, they're not only feasible, but encouraged in other languages such as Logo and Forth. Besides speeding execution, recursion produces compact, elegant code, as this example shows. Thanks for the demonstration.