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