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