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