new doc.mk; document numbering changes for 4.4BSD
[unix-history] / usr / src / lib / libcurses / PSD.doc / appen.C
CommitLineData
ea56bb60
KB
1.\" Copyright (c) 1980 The Regents of the University of California.
2.\" All rights reserved.
0499335a 3.\"
3edcb7c8 4.\" %sccs.include.redist.roff%
ea56bb60 5.\"
6294d633 6.\" @(#)appen.C 8.2 (Berkeley) %G%
0499335a 7.\"
e91b2015
EA
8.ie t .oh '\*(Ln Appendix A''PS1:18-%'
9.eh 'PS1:18-%''\*(Ln Appendix A'
10.el .he ''\fIAppendix A\fR''
0499335a
KM
11.bp
12.(x
13.ti 0
e91b2015 14.b "Appendix A"
0499335a
KM
15.)x
16.sh 1 "Examples" 1
17.pp
18Here we present a few examples
19of how to use the package.
20They attempt to be representative,
e91b2015
EA
21though not comprehensive. Further examples can be found in the games section
22of the source tree and in various utilities that use the screen such as
23.i systat(1) .
24.sh 2 "Screen Updating"
0499335a
KM
25.pp
26The following examples are intended to demonstrate
27the basic structure of a program
28using the screen updating sections of the package.
29Several of the programs require calculational sections
30which are irrelevant of to the example,
31and are therefore usually not included.
32It is hoped that the data structure definitions
33give enough of an idea to allow understanding
34of what the relevant portions do.
e91b2015
EA
35.sh 3 "Simple Character Output"
36.pp
37This program demonstrates how to set up a window and output characters to it.
38Also, it demonstrates how one might control the output to the window. If
39you run this program, you will get a demonstration of the character output
40chracteristics discussed in the above Character Output section.
41.(l I
42.so t2.gr
43.)l
44.sh 3 "A Small Screen Manipulator"
45.pp
46The next example follows the lines of the previous one but extends then to
47demonstrate the various othe uses of the package. Make sure you understand
48how this program works as it encompasses most of anything you will
49need to do with the package.
50.(l I
51.so t3.gr
52.)l
53.sh 3 "Twinkle"
0499335a
KM
54.pp
55This is a moderately simple program which prints
e91b2015 56patterns on the screen.
0499335a
KM
57It switches between patterns of asterisks,
58putting them on one by one in random order,
59and then taking them off in the same fashion.
60It is more efficient to write this
61using only the motion optimization,
62as is demonstrated below.
63.(l I
64.so twinkle1.gr
65.)l
e91b2015 66.sh 3 "Life"
0499335a 67.pp
4a3a8670 68This program fragment models the famous computer pattern game of life
0499335a
KM
69(Scientific American, May, 1974).
70The calculational routines create a linked list of structures
71defining where each piece is.
72Nothing here claims to be optimal,
73merely demonstrative.
4a3a8670 74This code, however,
0499335a
KM
75is a very good place to use the screen updating routines,
76as it allows them to worry about what the last position looked like,
77so you don't have to.
78It also demonstrates some of the input routines.
79.(l I
80.so life.gr
81.)l
e91b2015 82.sh 2 "Motion optimization"
0499335a
KM
83.pp
84The following example shows how motion optimization
85is written on its own.
86Programs which flit from one place to another without
87regard for what is already there
88usually do not need the overhead of both space and time
89associated with screen updating.
90They should instead use motion optimization.
e91b2015 91.sh 3 "Twinkle"
0499335a
KM
92.pp
93The
94.b twinkle
95program
96is a good candidate for simple motion optimization.
97Here is how it could be written
98(only the routines that have been changed are shown):
99.(l
100.so twinkle2.gr
101.)l