home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprocs / lindterp.icn < prev    next >
Text File  |  2001-05-02  |  2KB  |  74 lines

  1. ############################################################################
  2. #
  3. #    File:     lindterp.icn
  4. #
  5. #    Subject:  Procedure to interpret and draw L-System strings
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 2, 2001
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This procedure interpreters strings of characters produced by
  18. #  L-Systems and draws them using turtle graphics.
  19. #
  20. ############################################################################
  21. #
  22. #  Links:  lindrec, lindgen, turtle
  23. #
  24. ############################################################################
  25.  
  26. link lindrec
  27. link lindgen
  28. link turtle
  29.  
  30. global size
  31.  
  32. #  length is the length of line segments and delta is the amount of
  33. #  direction change.
  34.  
  35. procedure lindterp(x, y, lsys, gener, length, color, fnc)
  36.    local rewrite, delta, axiom, symbols, c
  37.  
  38.    /size := 500
  39.    /x := size / 2
  40.    /y := size / 2
  41.    rewrite := lsys.rewrite
  42.    axiom := lsys.axiom
  43.    delta := lsys.delta
  44.    /gener := lsys.gener
  45.    /length := lsys.length
  46.  
  47. #  The table symbols contains definitions for other symbols as
  48. #  string of other characters.  It remains to be seen how this
  49. #  will be represented.  Note also there is a potential for
  50. #  circularity and unbounded recursion.
  51.  
  52.    symbols := table()                # table of defined symbols
  53.  
  54.    TReset()
  55.    TGoto(x, y)
  56.  
  57.    every c := lindgen(!axiom, rewrite, gener) do
  58.       case c of {
  59.          "F":   TDraw(length)            # draw forward
  60.          "f":   TSkip(length)            # skip forward
  61.          "+":   TRight(delta)            # turn right
  62.          "-":   TLeft(delta)            # turn left
  63.          "[":   TSave()                # save state
  64.          "]":   TRestore()            # restore state
  65.                         # interpret defined symbol
  66.          default:   lindterp(\symbols[c], length, delta)
  67.          }                    # ignore other characters
  68.  
  69.    WFlush()
  70.  
  71.    return
  72.  
  73. end
  74.