xref: /original-bsd/lib/libcurses/PSD.doc/appen.C (revision 9eb838fd)
1 .\" Copyright (c) 1980 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms are permitted
5 .\" provided that the above copyright notice and this paragraph are
6 .\" duplicated in all such forms and that any documentation,
7 .\" advertising materials, and other materials related to such
8 .\" distribution and use acknowledge that the software was developed
9 .\" by the University of California, Berkeley.  The name of the
10 .\" University may not be used to endorse or promote products derived
11 .\" from this software without specific prior written permission.
12 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 .\"
16 .\"	@(#)appen.C	6.2 (Berkeley) 03/17/89
17 .\"
18 .ie t .oh '\*(Ln Appendix C''PS1:18-%'
19 .eh 'PS1:18-%''\*(Ln Appendix C'
20 .el .he ''\fIAppendix C\fR''
21 .bp
22 .(x
23 .ti 0
24 .b "Appendix C"
25 .)x
26 .sh 1 "Examples" 1
27 .pp
28 Here we present a few examples
29 of how to use the package.
30 They attempt to be representative,
31 though not comprehensive.
32 .sh 1 "Screen Updating"
33 .pp
34 The following examples are intended to demonstrate
35 the basic structure of a program
36 using the screen updating sections of the package.
37 Several of the programs require calculational sections
38 which are irrelevant of to the example,
39 and are therefore usually not included.
40 It is hoped that the data structure definitions
41 give enough of an idea to allow understanding
42 of what the relevant portions do.
43 The rest is left as an exercise to the reader,
44 and will not be on the final.
45 .sh 2 "Twinkle"
46 .pp
47 This is a moderately simple program which prints
48 pretty patterns on the screen
49 that might even hold your interest for 30 seconds or more.
50 It switches between patterns of asterisks,
51 putting them on one by one in random order,
52 and then taking them off in the same fashion.
53 It is more efficient to write this
54 using only the motion optimization,
55 as is demonstrated below.
56 .(l I
57 .so twinkle1.gr
58 .)l
59 .sh 2 "Life"
60 .pp
61 This program fragment models the famous computer pattern game of life
62 (Scientific American, May, 1974).
63 The calculational routines create a linked list of structures
64 defining where each piece is.
65 Nothing here claims to be optimal,
66 merely demonstrative.
67 This code, however,
68 is a very good place to use the screen updating routines,
69 as it allows them to worry about what the last position looked like,
70 so you don't have to.
71 It also demonstrates some of the input routines.
72 .(l I
73 .so life.gr
74 .)l
75 .sh 1 "Motion optimization"
76 .pp
77 The following example shows how motion optimization
78 is written on its own.
79 Programs which flit from one place to another without
80 regard for what is already there
81 usually do not need the overhead of both space and time
82 associated with screen updating.
83 They should instead use motion optimization.
84 .sh 2 "Twinkle"
85 .pp
86 The
87 .b twinkle
88 program
89 is a good candidate for simple motion optimization.
90 Here is how it could be written
91 (only the routines that have been changed are shown):
92 .(l
93 .so twinkle2.gr
94 .)l
95