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 | .\" |
6294d633 | 6 | .\" @(#)appen.C 8.2 (Berkeley) %G% |
0499335a | 7 | .\" |
e91b2015 EA |
8 | .ie t .oh '\*(Ln Appendix A''PS1:18-%' |
9 | .eh 'PS1:18-%''\*(Ln Appendix A' | |
10 | .el .he ''\fIAppendix A\fR'' | |
0499335a KM |
11 | .bp |
12 | .(x | |
13 | .ti 0 | |
e91b2015 | 14 | .b "Appendix A" |
0499335a KM |
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, | |
e91b2015 EA |
21 | though not comprehensive. Further examples can be found in the games section |
22 | of the source tree and in various utilities that use the screen such as | |
23 | .i systat(1) . | |
24 | .sh 2 "Screen Updating" | |
0499335a KM |
25 | .pp |
26 | The following examples are intended to demonstrate | |
27 | the basic structure of a program | |
28 | using the screen updating sections of the package. | |
29 | Several of the programs require calculational sections | |
30 | which are irrelevant of to the example, | |
31 | and are therefore usually not included. | |
32 | It is hoped that the data structure definitions | |
33 | give enough of an idea to allow understanding | |
34 | of what the relevant portions do. | |
e91b2015 EA |
35 | .sh 3 "Simple Character Output" |
36 | .pp | |
37 | This program demonstrates how to set up a window and output characters to it. | |
38 | Also, it demonstrates how one might control the output to the window. If | |
39 | you run this program, you will get a demonstration of the character output | |
40 | chracteristics discussed in the above Character Output section. | |
41 | .(l I | |
42 | .so t2.gr | |
43 | .)l | |
44 | .sh 3 "A Small Screen Manipulator" | |
45 | .pp | |
46 | The next example follows the lines of the previous one but extends then to | |
47 | demonstrate the various othe uses of the package. Make sure you understand | |
48 | how this program works as it encompasses most of anything you will | |
49 | need to do with the package. | |
50 | .(l I | |
51 | .so t3.gr | |
52 | .)l | |
53 | .sh 3 "Twinkle" | |
0499335a KM |
54 | .pp |
55 | This is a moderately simple program which prints | |
e91b2015 | 56 | patterns on the screen. |
0499335a KM |
57 | It switches between patterns of asterisks, |
58 | putting them on one by one in random order, | |
59 | and then taking them off in the same fashion. | |
60 | It is more efficient to write this | |
61 | using only the motion optimization, | |
62 | as is demonstrated below. | |
63 | .(l I | |
64 | .so twinkle1.gr | |
65 | .)l | |
e91b2015 | 66 | .sh 3 "Life" |
0499335a | 67 | .pp |
4a3a8670 | 68 | This program fragment models the famous computer pattern game of life |
0499335a KM |
69 | (Scientific American, May, 1974). |
70 | The calculational routines create a linked list of structures | |
71 | defining where each piece is. | |
72 | Nothing here claims to be optimal, | |
73 | merely demonstrative. | |
4a3a8670 | 74 | This code, however, |
0499335a KM |
75 | is a very good place to use the screen updating routines, |
76 | as it allows them to worry about what the last position looked like, | |
77 | so you don't have to. | |
78 | It also demonstrates some of the input routines. | |
79 | .(l I | |
80 | .so life.gr | |
81 | .)l | |
e91b2015 | 82 | .sh 2 "Motion optimization" |
0499335a KM |
83 | .pp |
84 | The following example shows how motion optimization | |
85 | is written on its own. | |
86 | Programs which flit from one place to another without | |
87 | regard for what is already there | |
88 | usually do not need the overhead of both space and time | |
89 | associated with screen updating. | |
90 | They should instead use motion optimization. | |
e91b2015 | 91 | .sh 3 "Twinkle" |
0499335a KM |
92 | .pp |
93 | The | |
94 | .b twinkle | |
95 | program | |
96 | is a good candidate for simple motion optimization. | |
97 | Here is how it could be written | |
98 | (only the routines that have been changed are shown): | |
99 | .(l | |
100 | .so twinkle2.gr | |
101 | .)l |