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