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 / progs / ranstars.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  93 lines

  1. ############################################################################
  2. #
  3. #    File:     ranstars.icn
  4. #
  5. #    Subject:  Program to display star field
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     March 2, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #     This program display a random field of "stars" on an ANSI terminal.
  18. #  It displays stars at randomly chosen positions on the screen until
  19. #  the specified maximum number is reached. It then extinguishes existing
  20. #  stars and creates new ones for the specified steady-state time, after
  21. #  which the stars are extinguished, one by one.
  22. #
  23. #     The programming technique is worth noting. It is originally due to
  24. #  Steve Wampler.
  25. #
  26. #     The options are:
  27. #
  28. #    -m n    maximum number of stars, default 10.
  29. #
  30. #    -t n    length of steady-state time before stars are extinguished,
  31. #          default 50.
  32. #
  33. #    -s c    the character to be used for "stars", default *. If
  34. #          more than one character is given, only the first is
  35. #          used.
  36. #
  37. ############################################################################
  38. #
  39. #  Requires:  co-expressions, ANSI terminal
  40. #
  41. ############################################################################
  42. #
  43. #  Links:  ansi, options, random
  44. #
  45. ############################################################################
  46.  
  47. link ansi
  48. link options
  49. link random
  50.  
  51. procedure main(args)
  52.    local length, steady, star, opts, r, ran1, ran2
  53.  
  54.    randomize()
  55.  
  56.    opts := options(args,"m+t+s:")
  57.    length := \opts["m"] | 10
  58.    steady := \opts["t"] | 50
  59.    star := \opts["s"] | "*"
  60.    star := star[1]
  61.    r := 0
  62.  
  63.    ran1 := create 2(&random :=: r, |?(24 | 80), &random <-> r)
  64.    ran2 := ^ran1
  65.    clear()                # clear the screen
  66.    every 1 to length do            # start up the universe
  67.       place(ran1,star)
  68.    every 1 to steady do {        # steady state condition
  69.       place(ran2," ")            # clean up the beginning
  70.       place(ran1,star)            # create more
  71.       }
  72.    every 1 to length do            # and the universe dies
  73.       place(ran2," ")            # clean up the end
  74.    clear()                # clear the screen
  75.    home()                # home the cursor
  76. end
  77.  
  78. procedure clear()
  79.    ED()
  80.    return
  81. end
  82.  
  83. procedure home()
  84.    CUP(1,1)
  85.    return
  86. end
  87.  
  88. procedure place(e,s)
  89.    CUP(@e,@e)
  90.    writes(s)
  91.    return
  92. end
  93.