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