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 / gdocs / gtrace.txt next >
Text File  |  2001-05-25  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                          Graphic Traces
  8.  
  9.  
  10. Introduction
  11.  
  12.    Several graphical components of the Icon program library rely
  13. on the concept of graphic traces.  A graphic trace is simply a
  14. sequence of points.
  15.  
  16.    The purpose of graphic traces is to separate the computation
  17. of the geometrical components of figures from the rendering of
  18. them.  This allows procedures that generate points to be used in
  19. a variety of ways.  For example, they can be used by rendering
  20. procedures to draw figures.  Alternatively, the points need not
  21. produce any figure at all, but they simply could be written to a
  22. file for later use or analysis.  This approach also allows dif-
  23. ferent kinds of rendering procedures to use the same graphic
  24. traces.  For example, the rendering might be done directly by
  25. drawing functions like XDrawPoint() or by using turtle graphics.
  26. The same graphic trace - sequence of points - also can be used in
  27. different ways.  For example, individual points can be draw, suc-
  28. cessive points can be connected by lines, or the points can be
  29. used as locii for drawing other figures.
  30.  
  31. Points
  32.  
  33.    In the abstract, a point is a location in n-dimensional space.
  34. We'll limit our considerations to two dimensions, although most
  35. of the ideas are easily generalized.  The natural concrete
  36. representation of a point is an object with coordinate values.  A
  37. record provides the natural programming interpretation of this:
  38.  
  39.         record Point(x, y)
  40.  
  41. Thus Point(200, 100) creates a point at with x-y coordinates
  42. 200,100.
  43.  
  44.    A typical graphic trace procedure looks like this:
  45.  
  46.         procedure polygon(n, r)
  47.            local angle, incr
  48.  
  49.            angle := 0
  50.            incr := 2 * &pi / n
  51.  
  52.            every 1 to n do {
  53.               suspend Point(r * cos(angle), r * sin(angle))
  54.               angle +:= incr
  55.               }
  56.  
  57.         end
  58.  
  59.  
  60.    Dealing with points as objects with coordinate values is very
  61.  
  62.  
  63.  
  64.                               - 1 -
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. natural and intuitively appealing.  The drawing functions, how-
  74. ever, require coordinate positions as x-y argument pairs, as in
  75.  
  76.         XDrawLine(200, 100, 300, 200)
  77.  
  78. which draws a line from 200,100 to 300,200.
  79.  
  80.    There are good reasons why the drawling functions require x-y
  81. argument pairs.  It is more efficient to represent points in this
  82. way, and in some cases it is simpler to compute a series of x-y
  83. values than it is to create points.
  84.  
  85.    Argument pairs can be stored in lists, as in
  86.  
  87.         point_list := [p1.x, p1.y, p2.x, p2.y]
  88.  
  89. and supplied to drawing functions using list invocation:
  90.  
  91.         XDrawLine ! point_list
  92.  
  93.  
  94.    There really is no way to reconcile the two different
  95. representation of points, one as objects with coordinate values
  96. and the other as argument pairs.  Conversion between the two
  97. representations is simple, however, and utility procedures are
  98. provided for this.  Since graphic traces are designed to provide
  99. a high level of abstraction, we will deal with points as objects
  100. and leave the conversion to argument pairs, when needed, to the
  101. rendering domain.
  102.  
  103. Producing_and_Using_Graphic_Traces
  104.  
  105.    The Icon program library currently contains several collec-
  106. tions of procedures for generating graphic traces:
  107.  
  108.         curves.icn      various plane curves
  109.         rstars.icn      regular stars
  110.         fstars.icn      ``fractal stars''
  111.  
  112. See these procedures for examples of how graphic traces can be
  113. produced.
  114.  
  115.    The procedures in gtrace.icn and xgrtrace.icn provide various
  116. operations on graphic traces.
  117.  
  118.    In order to perform a sequence of operations on graphic
  119. traces, it is helpful to use ``packaged'' calls, in which a pro-
  120. cedure and an argument list for it are encapsulated in an object.
  121. See calls.icn.
  122.  
  123.    Two programs in the current library use graphic traces:
  124. rstarlab.icn and fstarlab.icn. These programs use the procedures
  125. rstars.icn and fstars.icn mentioned earlier.  These programs
  126. allow points from graphic traces to be used in various ways.
  127.  
  128.  
  129.  
  130.                               - 2 -
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. Turtle graphics (see turtle.icn) are used by default for render-
  140. ing.
  141.  
  142. Limitations_of_Graphic_Traces
  143.  
  144.    A graphic trace is just a sequence of points. It contains no
  145. context for these points, other than the order in which they
  146. occur. For example, there is no information in a graphic trace
  147. (unless it is contrived) to identify transitions between parts of
  148. a composite object.
  149.  
  150.    Procedures that use graphic traces can, of course, use
  151. separately derived contextual information or coding techniques,
  152. such as buffering the points, to circumvent some kinds of prob-
  153. lems.
  154.  
  155.    By their nature, graphic graces are most appropriate for
  156. applications in which all points (except perhaps the first) are
  157. treated in the same way.
  158.  
  159.  
  160.  
  161. Ralph E. Griswold
  162.  
  163. Department of Computer Science
  164. The University of Arizona
  165.  
  166. June 8, 1993
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                               - 3 -
  197.  
  198.  
  199.