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