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