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