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