Everything changes. Appendix C becomes appendix A.
[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.\"
3edcb7c8 6.\" @(#)appen.C 6.3 (Berkeley) %G%
0499335a 7.\"
4a3a8670
KM
8.ie t .oh '\*(Ln Appendix C''PS1:18-%'
9.eh 'PS1:18-%''\*(Ln Appendix C'
0499335a
KM
10.el .he ''\fIAppendix C\fR''
11.bp
12.(x
13.ti 0
14.b "Appendix C"
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,
21though not comprehensive.
22.sh 1 "Screen Updating"
23.pp
24The following examples are intended to demonstrate
25the basic structure of a program
26using the screen updating sections of the package.
27Several of the programs require calculational sections
28which are irrelevant of to the example,
29and are therefore usually not included.
30It is hoped that the data structure definitions
31give enough of an idea to allow understanding
32of what the relevant portions do.
33The rest is left as an exercise to the reader,
34and will not be on the final.
35.sh 2 "Twinkle"
36.pp
37This is a moderately simple program which prints
38pretty patterns on the screen
39that might even hold your interest for 30 seconds or more.
40It switches between patterns of asterisks,
41putting them on one by one in random order,
42and then taking them off in the same fashion.
43It is more efficient to write this
44using only the motion optimization,
45as is demonstrated below.
46.(l I
47.so twinkle1.gr
48.)l
49.sh 2 "Life"
50.pp
4a3a8670 51This program fragment models the famous computer pattern game of life
0499335a
KM
52(Scientific American, May, 1974).
53The calculational routines create a linked list of structures
54defining where each piece is.
55Nothing here claims to be optimal,
56merely demonstrative.
4a3a8670 57This code, however,
0499335a
KM
58is a very good place to use the screen updating routines,
59as it allows them to worry about what the last position looked like,
60so you don't have to.
61It also demonstrates some of the input routines.
62.(l I
63.so life.gr
64.)l
65.sh 1 "Motion optimization"
66.pp
67The following example shows how motion optimization
68is written on its own.
69Programs which flit from one place to another without
70regard for what is already there
71usually do not need the overhead of both space and time
72associated with screen updating.
73They should instead use motion optimization.
74.sh 2 "Twinkle"
75.pp
76The
77.b twinkle
78program
79is a good candidate for simple motion optimization.
80Here is how it could be written
81(only the routines that have been changed are shown):
82.(l
83.so twinkle2.gr
84.)l