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