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 / strpchrt.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  127 lines

  1. ############################################################################
  2. #
  3. #    File:     strpchrt.icn
  4. #
  5. #    Subject:  Procedure for dynamic stripchart for windows
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     August 14, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    A stripchart models a continuous roll of paper that is marked along
  18. #    the right edge while it moves continuously to the left.  This is
  19. #    also known as a chart recording.
  20. #
  21. #    stripchart(window, x, y, width, height)    creates a stripchart.
  22. #
  23. #    sadvance(sc)                advances a stripchart.
  24. #
  25. #    smark(sc, y1, y2)            marks a stripchart.
  26. #
  27. ############################################################################
  28. #
  29. #
  30. #   stripchart(window, x, y, width, height)
  31. #
  32. #    establishes a stripchart and returns a record sc for use with
  33. #    other procedures.
  34. #
  35. #    The chart can be marked by calling smark() or by drawing directly
  36. #    at location (sc.x, y) where y is arbitrary.
  37. #
  38. #   sadvance(sc)
  39. #
  40. #    advances the stripchart by one pixel.
  41. #
  42. #   smark(sc, y1, y2)
  43. #
  44. #    marks the current position of the stripchart from y1 to y2.  y2 may
  45. #    be omitted, in which case a single pixel at (sc.x, y1) is marked.
  46. #
  47. #    If the chart has not been advanced since the last mark at y1,
  48. #    nothing happens.
  49. #
  50. ############################################################################
  51. #
  52. #  Requires:  Version 9 graphics
  53. #
  54. ############################################################################
  55.  
  56. record StripChart_Rec(win, x0, y, w, h, x, n, last)
  57.  
  58.  
  59. ## stripchart(win, x, y, w, h) - create stripchart of size w by h at (x, y)
  60.  
  61. procedure stripchart(win, x, y, w, h)        #: create stripchart
  62.    if type(win) ~== "window" then
  63.       return stripchart((\&window | runerr(140)), win, x, y, w)
  64.  
  65.    /x := -WAttrib(win, "dx")
  66.    /y := -WAttrib(win, "dy")
  67.    /w := WAttrib(win, "width") - (x + WAttrib(win, "dx"))
  68.    /h := WAttrib(win, "height") - (y + WAttrib(win, "dy"))
  69.  
  70.    if w < 0 then
  71.       x -:= (w := -w)
  72.    if h < 0 then
  73.       y -:= (h := -h)
  74.  
  75.    EraseArea(win, x, y, w, h)
  76.    return StripChart_Rec(win, x, y, w, h, x, 0, list(y + h, -1))
  77. end
  78.  
  79.  
  80. ## sadvance(sc, n) - advance stripchart n pixels (default 1)
  81.  
  82. procedure sadvance(sc, n)            #: advance stripchart
  83.  
  84.    /n := 1
  85.    every 1 to n do {
  86.       if sc.x < (sc.x0 + sc.w - 1) then
  87.          sc.x +:= 1
  88.       else
  89.          CopyArea(sc.win, sc.x0 + 1, sc.y, sc.w - 1, sc.h, sc.x0, sc.y)
  90.       EraseArea(sc.win, sc.x, sc.y, 1, sc.h)
  91.       sc.n +:= 1
  92.       }
  93.    return
  94. end
  95.  
  96.  
  97. ## smark (sc, y1, y2) - mark stripchart from y1 to y2.
  98.  
  99. procedure smark(sc, y1, y2)            #: mark stripchart
  100.    y1 := integer(y1)
  101.    if sc.last[y1] <:= sc.n then
  102.       DrawLine(sc.win, sc.x, y1, sc.x, \y2) | DrawPoint(sc.win, sc.x, y1)
  103.    return
  104. end
  105.  
  106.  
  107.  
  108. #  ## test program.
  109. #  #
  110. #  #  usage:  stripchart [n]
  111. #  #
  112. #  link graphics
  113. #  procedure main(args)
  114. #     local win, sc, n, y, d
  115. #     Window("size=500,200", args)
  116. #     n := integer(args[1]) | 700
  117. #     sc := stripchart()
  118. #     y := 80
  119. #     d := 40
  120. #     every 1 to n do {
  121. #        smark(sc, y +:= 2 * (?0 - ?0))
  122. #        smark(sc, y + (d +:= 2 * (?0 - ?0)))
  123. #        sadvance(sc)
  124. #        }
  125. #     WDone()
  126. #     end
  127.