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. Neither the name of the University nor the names of its contributors 13 .\" may be used to endorse or promote products derived from this software 14 .\" without specific prior written permission. 15 .\" 16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 .\" SUCH DAMAGE. 27 .\" 28 .\" @(#)appen.C 8.1 (Berkeley) 6/8/93 29 .\" 30 .ie t .oh '\*(Ln Appendix A''PS1:19-%' 31 .eh 'PS1:19-%''\*(Ln Appendix A' 32 .el .he ''\fIAppendix A\fR'' 33 .bp 34 .(x 35 .ti 0 36 .b "Appendix A" 37 .)x 38 .sh 1 "Examples" 1 39 .pp 40 Here we present a few examples 41 of how to use the package. 42 They attempt to be representative, 43 though not comprehensive. Further examples can be found in the games section 44 of the source tree and in various utilities that use the screen such as 45 .i systat(1) . 46 .sh 2 "Screen Updating" 47 .pp 48 The following examples are intended to demonstrate 49 the basic structure of a program 50 using the screen updating sections of the package. 51 Several of the programs require calculational sections 52 which are irrelevant of to the example, 53 and are therefore usually not included. 54 It is hoped that the data structure definitions 55 give enough of an idea to allow understanding 56 of what the relevant portions do. 57 .sh 3 "Simple Character Output" 58 .pp 59 This program demonstrates how to set up a window and output characters to it. 60 Also, it demonstrates how one might control the output to the window. If 61 you run this program, you will get a demonstration of the character output 62 chracteristics discussed in the above Character Output section. 63 .(l I 64 .so t2.gr 65 .)l 66 .sh 3 "A Small Screen Manipulator" 67 .pp 68 The next example follows the lines of the previous one but extends then to 69 demonstrate the various othe uses of the package. Make sure you understand 70 how this program works as it encompasses most of anything you will 71 need to do with the package. 72 .(l I 73 .so t3.gr 74 .)l 75 .sh 3 "Twinkle" 76 .pp 77 This is a moderately simple program which prints 78 patterns on the screen. 79 It switches between patterns of asterisks, 80 putting them on one by one in random order, 81 and then taking them off in the same fashion. 82 It is more efficient to write this 83 using only the motion optimization, 84 as is demonstrated below. 85 .(l I 86 .so twinkle1.gr 87 .)l 88 .sh 3 "Life" 89 .pp 90 This program fragment models the famous computer pattern game of life 91 (Scientific American, May, 1974). 92 The calculational routines create a linked list of structures 93 defining where each piece is. 94 Nothing here claims to be optimal, 95 merely demonstrative. 96 This code, however, 97 is a very good place to use the screen updating routines, 98 as it allows them to worry about what the last position looked like, 99 so you don't have to. 100 It also demonstrates some of the input routines. 101 .(l I 102 .so life.gr 103 .)l 104 .sh 2 "Motion optimization" 105 .pp 106 The following example shows how motion optimization 107 is written on its own. 108 Programs which flit from one place to another without 109 regard for what is already there 110 usually do not need the overhead of both space and time 111 associated with screen updating. 112 They should instead use motion optimization. 113 .sh 3 "Twinkle" 114 .pp 115 The 116 .b twinkle 117 program 118 is a good candidate for simple motion optimization. 119 Here is how it could be written 120 (only the routines that have been changed are shown): 121 .(l 122 .so twinkle2.gr 123 .)l 124