BSD 4_3_Net_2 release
[unix-history] / usr / src / share / doc / ps1 / 18.curses / appen.C
CommitLineData
ea56bb60
KB
1.\" Copyright (c) 1980 The Regents of the University of California.
2.\" All rights reserved.
0499335a 3.\"
af359dea
C
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.
ea56bb60 19.\"
af359dea
C
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.\" @(#)appen.C 6.3 (Berkeley) 4/17/91
0499335a 33.\"
4a3a8670
KM
34.ie t .oh '\*(Ln Appendix C''PS1:18-%'
35.eh 'PS1:18-%''\*(Ln Appendix C'
0499335a
KM
36.el .he ''\fIAppendix C\fR''
37.bp
38.(x
39.ti 0
40.b "Appendix C"
41.)x
42.sh 1 "Examples" 1
43.pp
44Here we present a few examples
45of how to use the package.
46They attempt to be representative,
47though not comprehensive.
48.sh 1 "Screen Updating"
49.pp
50The following examples are intended to demonstrate
51the basic structure of a program
52using the screen updating sections of the package.
53Several of the programs require calculational sections
54which are irrelevant of to the example,
55and are therefore usually not included.
56It is hoped that the data structure definitions
57give enough of an idea to allow understanding
58of what the relevant portions do.
59The rest is left as an exercise to the reader,
60and will not be on the final.
61.sh 2 "Twinkle"
62.pp
63This is a moderately simple program which prints
64pretty patterns on the screen
65that might even hold your interest for 30 seconds or more.
66It switches between patterns of asterisks,
67putting them on one by one in random order,
68and then taking them off in the same fashion.
69It is more efficient to write this
70using only the motion optimization,
71as is demonstrated below.
72.(l I
73.so twinkle1.gr
74.)l
75.sh 2 "Life"
76.pp
4a3a8670 77This program fragment models the famous computer pattern game of life
0499335a
KM
78(Scientific American, May, 1974).
79The calculational routines create a linked list of structures
80defining where each piece is.
81Nothing here claims to be optimal,
82merely demonstrative.
4a3a8670 83This code, however,
0499335a
KM
84is a very good place to use the screen updating routines,
85as it allows them to worry about what the last position looked like,
86so you don't have to.
87It also demonstrates some of the input routines.
88.(l I
89.so life.gr
90.)l
91.sh 1 "Motion optimization"
92.pp
93The following example shows how motion optimization
94is written on its own.
95Programs which flit from one place to another without
96regard for what is already there
97usually do not need the overhead of both space and time
98associated with screen updating.
99They should instead use motion optimization.
100.sh 2 "Twinkle"
101.pp
102The
103.b twinkle
104program
105is a good candidate for simple motion optimization.
106Here is how it could be written
107(only the routines that have been changed are shown):
108.(l
109.so twinkle2.gr
110.)l