Commit | Line | Data |
---|---|---|
15637ed4 RG |
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, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
78ed81a3 | 32 | .\" from: @(#)appen.C 6.3 (Berkeley) 4/17/91 |
33 | .\" appen.C,v 1.2 1993/08/01 18:23:16 mycroft Exp | |
15637ed4 RG |
34 | .\" |
35 | .ie t .oh '\*(Ln Appendix C''PS1:18-%' | |
36 | .eh 'PS1:18-%''\*(Ln Appendix C' | |
37 | .el .he ''\fIAppendix C\fR'' | |
38 | .bp | |
39 | .(x | |
40 | .ti 0 | |
41 | .b "Appendix C" | |
42 | .)x | |
43 | .sh 1 "Examples" 1 | |
44 | .pp | |
45 | Here we present a few examples | |
46 | of how to use the package. | |
47 | They attempt to be representative, | |
48 | though not comprehensive. | |
49 | .sh 1 "Screen Updating" | |
50 | .pp | |
51 | The following examples are intended to demonstrate | |
52 | the basic structure of a program | |
53 | using the screen updating sections of the package. | |
54 | Several of the programs require calculational sections | |
55 | which are irrelevant of to the example, | |
56 | and are therefore usually not included. | |
57 | It is hoped that the data structure definitions | |
58 | give enough of an idea to allow understanding | |
59 | of what the relevant portions do. | |
60 | The rest is left as an exercise to the reader, | |
61 | and will not be on the final. | |
62 | .sh 2 "Twinkle" | |
63 | .pp | |
64 | This is a moderately simple program which prints | |
65 | pretty patterns on the screen | |
66 | that might even hold your interest for 30 seconds or more. | |
67 | It switches between patterns of asterisks, | |
68 | putting them on one by one in random order, | |
69 | and then taking them off in the same fashion. | |
70 | It is more efficient to write this | |
71 | using only the motion optimization, | |
72 | as is demonstrated below. | |
73 | .(l I | |
74 | .so twinkle1.gr | |
75 | .)l | |
76 | .sh 2 "Life" | |
77 | .pp | |
78 | This program fragment models the famous computer pattern game of life | |
79 | (Scientific American, May, 1974). | |
80 | The calculational routines create a linked list of structures | |
81 | defining where each piece is. | |
82 | Nothing here claims to be optimal, | |
83 | merely demonstrative. | |
84 | This code, however, | |
85 | is a very good place to use the screen updating routines, | |
86 | as it allows them to worry about what the last position looked like, | |
87 | so you don't have to. | |
88 | It also demonstrates some of the input routines. | |
89 | .(l I | |
90 | .so life.gr | |
91 | .)l | |
92 | .sh 1 "Motion optimization" | |
93 | .pp | |
94 | The following example shows how motion optimization | |
95 | is written on its own. | |
96 | Programs which flit from one place to another without | |
97 | regard for what is already there | |
98 | usually do not need the overhead of both space and time | |
99 | associated with screen updating. | |
100 | They should instead use motion optimization. | |
101 | .sh 2 "Twinkle" | |
102 | .pp | |
103 | The | |
104 | .b twinkle | |
105 | program | |
106 | is a good candidate for simple motion optimization. | |
107 | Here is how it could be written | |
108 | (only the routines that have been changed are shown): | |
109 | .(l | |
110 | .so twinkle2.gr | |
111 | .)l |