home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / bsd / curses / doc / appen.c < prev    next >
Encoding:
Text File  |  1991-04-17  |  4.1 KB  |  111 lines

  1. .\" Copyright (c) 1980 The Regents of the University of California.
  2. .\" All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\"    notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\"    notice, this list of conditions and the following disclaimer in the
  11. .\"    documentation and/or other materials provided with the distribution.
  12. .\" 3. All advertising materials mentioning features or use of this software
  13. .\"    must display the following acknowledgement:
  14. .\"    This product includes software developed by the University of
  15. .\"    California, Berkeley and its contributors.
  16. .\" 4. Neither the name of the University nor the names of its contributors
  17. .\"    may be used to endorse or promote products derived from this software
  18. .\"    without specific prior written permission.
  19. .\"
  20. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. .\" SUCH DAMAGE.
  31. .\"
  32. .\"    @(#)appen.C    6.3 (Berkeley) 4/17/91
  33. .\"
  34. .ie t .oh '\*(Ln Appendix C''PS1:18-%'
  35. .eh 'PS1:18-%''\*(Ln Appendix C'
  36. .el .he ''\fIAppendix C\fR''
  37. .bp
  38. .(x
  39. .ti 0
  40. .b "Appendix C"
  41. .)x
  42. .sh 1 "Examples" 1
  43. .pp
  44. Here we present a few examples
  45. of how to use the package.
  46. They attempt to be representative,
  47. though not comprehensive.
  48. .sh 1 "Screen Updating"
  49. .pp
  50. The following examples are intended to demonstrate
  51. the basic structure of a program
  52. using the screen updating sections of the package.
  53. Several of the programs require calculational sections
  54. which are irrelevant of to the example,
  55. and are therefore usually not included.
  56. It is hoped that the data structure definitions
  57. give enough of an idea to allow understanding
  58. of what the relevant portions do.
  59. The rest is left as an exercise to the reader,
  60. and will not be on the final.
  61. .sh 2 "Twinkle"
  62. .pp
  63. This is a moderately simple program which prints
  64. pretty patterns on the screen
  65. that might even hold your interest for 30 seconds or more.
  66. It switches between patterns of asterisks,
  67. putting them on one by one in random order,
  68. and then taking them off in the same fashion.
  69. It is more efficient to write this
  70. using only the motion optimization,
  71. as is demonstrated below.
  72. .(l I
  73. .so twinkle1.gr
  74. .)l
  75. .sh 2 "Life"
  76. .pp
  77. This program fragment models the famous computer pattern game of life
  78. (Scientific American, May, 1974).
  79. The calculational routines create a linked list of structures
  80. defining where each piece is.
  81. Nothing here claims to be optimal,
  82. merely demonstrative.
  83. This code, however,
  84. is a very good place to use the screen updating routines,
  85. as it allows them to worry about what the last position looked like,
  86. so you don't have to.
  87. It also demonstrates some of the input routines.
  88. .(l I
  89. .so life.gr
  90. .)l
  91. .sh 1 "Motion optimization"
  92. .pp
  93. The following example shows how motion optimization
  94. is written on its own.
  95. Programs which flit from one place to another without
  96. regard for what is already there
  97. usually do not need the overhead of both space and time
  98. associated with screen updating.
  99. They should instead use motion optimization.
  100. .sh 2 "Twinkle"
  101. .pp
  102. The
  103. .b twinkle
  104. program
  105. is a good candidate for simple motion optimization.
  106. Here is how it could be written
  107. (only the routines that have been changed are shown):
  108. .(l
  109. .so twinkle2.gr
  110. .)l
  111.