home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-02-20 | 62.5 KB | 1,330 lines |
- Newsgroups: comp.sources.misc
- organization: MIT Lincoln Laboratory, Lexington MA
- subject: v10i077: Continental Drift Simulator part 1/2
- from: davea@ll-vlsi.arpa (Dave Allen)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 10, Issue 77
- Submitted-by: davea@ll-vlsi.arpa (Dave Allen)
- Archive-name: tec/part01
-
- This is source for a continental drift simulator that has nice graphics
- on Suns, IBM PCs, and Amigas. It will produce text output on any Unix
- machine.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: tec-v3/README-v3 tec-v3/tec.out.1 tec-v3/tec.out.2
- # tec-v3/tec.out.3 tec-v3/howtorun.doc tec-v3/params.doc
- # tec-v3/technical.doc tec-v3/ami.c tec-v3/unix.c tec-v3/sun.c
- # tec-v3/const.h tec-v3/tec3.c
- # Wrapped by davea@vdd on Fri Feb 16 08:39:14 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'tec-v3/README-v3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/README-v3'\"
- else
- echo shar: Extracting \"'tec-v3/README-v3'\" \(3537 characters\)
- sed "s/^X//" >'tec-v3/README-v3' <<'END_OF_FILE'
- This is the README file for Version 3 of tec, a plate tectonic
- simulator. It is written in C and runs on: any UN*X machine using text
- or PostScript output; Amiga with nice color graphics and mouse support;
- IBM PC with Turbo C and CGA/MCGA/EGA/VGA; Sun-3s and Sun-4s using SunView.
- Copyright (c) 1990 by David Allen. You may distribute this freely as long
- as you leave my name and copyright notice intact.
- X
- I'd really like your comments and feedback; send e-mail to
- davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
- Maynard, MA 01754.
- X
- Version history:
- X1. Posted to rec.games.frp and rec.games.programmer on 11 / 15 / 89
- X - Runs only on Amiga, produces long text summary.
- X - Includes PostScript translator for any PostScript printer.
- X2. (Unreleased)
- X - Added text-only mode so it runs on UN*X machines.
- X - Added summary text output mode that fits on 80-character lines.
- X - PostScript support merged into main program.
- X3. Posted to comp.sources.misc on 2 / 15 / 90.
- X - Parameters can come from an input file (see params.doc).
- X - Graphics ported to Sun 3 and 4 systems.
- X - Ported to IBM PC by Peter Lind.
- X
- Credits:
- Brian Love - conversion to Amiga Lattice C 5.02, Amiga beta tester.
- Peter Lind - port to IBM PC Turbo C with CGA/MCGA/EGA/VGA.
- X
- X
- WHAT DOES THE TECTONIC SIMULATOR DO?
- X
- TEC draws a map of some imaginary world and puts one big continent on it.
- The program then graphically simulates the breakup of this supercontinent by
- rifts and the drifting of the continents. Mountains are built by
- subsuming and by continental collision, and are reduced by erosion. As
- more time passes, the continents tend to drift back into a supercontinent
- and split up again, forming what some authors call a "supercontinent cycle."
- X
- The program produces a map of an imaginary world which contains realistic
- looking mountain ranges and continents which sometimes look like they fit
- together (like South America and Africa on Earth).
- X
- I've included some sample output in the files tec.out.[1-3]; they are
- short text files. 0's indicate ocean, 1's indicate land, and 2's indicate
- mountains. Take a look.
- X
- X
- WHAT SYSTEMS DOES IT RUN ON?
- X
- Version 3 runs on a number of platforms. Nongraphics mode runs on
- Suns and Vaxen for sure, and should run on any UN*X system. Minimal
- changes should be needed (random number generator) to run on any
- system with a C compiler. Amiga systems tested include the Amiga 500,
- X1000 or 2000 with 1 meg, WB 1.2 or 1.3, and Lattice C 4.0 or 5.02.
- Sun graphics were tested on a Sun-3/60 and on a Sparcstation-1, each
- using SunView and SunOS 4.0.3. The IBM PC version will run on any
- XXT/AT/100% compatible clone using Turbo C 2.0+.
- X
- X
- WHAT FILES ARE INCLUDED IN THIS RELEASE?
- X
- README-v3 - This file
- tec.out.[1-3] - sample text output files produced on a Sun-3
- howtorun.doc - Instructions for compiling tec on the various machines
- technical.doc - Technical description of program algorithms
- params.doc - Describes all the adjustable parameters
- const.h - Some common defines with magic numbers
- var.h - Include file for adjustable parameters
- tec1.c - Contains most of the interesting functions
- tec2.c - Contains functions to create rifts and split landmasses
- tec3.c - Parameter reading functions
- ami.c - Amiga-specific graphics and mouse functions
- unix.c - UN*X-specific text output routines
- sun.c - Sun graphics routines
- ibmpc.c - IBM PC graphics routines, Turbo C 2.0+
- tec.mak - Turbo C make file
- END_OF_FILE
- if test 3537 -ne `wc -c <'tec-v3/README-v3'`; then
- echo shar: \"'tec-v3/README-v3'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/README-v3'
- fi
- if test -f 'tec-v3/tec.out.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/tec.out.1'\"
- else
- echo shar: Extracting \"'tec-v3/tec.out.1'\" \(3504 characters\)
- sed "s/^X//" >'tec-v3/tec.out.1' <<'END_OF_FILE'
- X000000000000000000000000000000000000222222221110000000000000000000000000
- X000000000000001111110000000000000001222111111100000000000000000000000000
- X000000000000011111111000000000000011211111111000000000000000000000000000
- X000000000001111111111111000000000111111111110000001110000000000000000000
- X000000000011111111111111100000000111111111100000011100000000000000000000
- X000000000011111111111111110000001111111111000000011110000000000000000000
- X000000000111111111111111111000011111111100000000111110000000000000000000
- X000000000111111111111111111100111111111000000001111110000000000000000000
- X000000000111111111111111111001111111110000000011111111000000000000000000
- X000000000111111111111111111111111111100000000111111111000000000000000000
- X000000000111111111111111111111111110000000011111111111000000000000000000
- X000000000111111111111111111111111100000000111111111111000000000000000000
- X000000000111111111112211111222110000000001111111111110000000000000000000
- X000000000111111111122222221111100000000011111221111111000000000000000000
- X000000000111111111122222111000000000001111122212221111100000000000000000
- X000000000011111111112222100000000000011112222212111111100000000000000000
- X000000000011111111111121000000000011111222222211111111110000000000000000
- X000000000011111111111010000000000111112222222211111111111000000000000000
- X000000000011111111100000000001111111222221112111111111111100000000000000
- X000000000011111111000000000112211222222211122111111111111111000000000000
- X000000000011111111000000001211111222221111111111111111111110000000000000
- X000000000000001110000000011111122222111111111111111111111110000000000000
- X000000000000000000000000111111222221111111111111111111100000000000000000
- X000000000000000000000001111212222111111111111101111111000000000000000000
- X000000000000000000000001222122221111111111111001111111000000000000000000
- X000000000000000000000001222222111111111111111101111110000000000000000000
- X000000000000000000000001222111111111111111111100110000000000000000000000
- X000000000000000000000001211111111111111111111000000000000000000000000000
- X000000000000000000000001111111111111111111111000000000000000000000000000
- X000000000000000000000000111111111111111111110000000000000000000000000000
- X000000000000000000000000111111111111111100000000000000000000000000000000
- X000000000000000000000000111111111111111000000000000000000000000000000000
- X000000000000000000000000011011111111100000000000000000000000000000000000
- X000000000000000000000000000011111111000000000000000000000000000000000000
- X000000000000000000000000000000110000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- END_OF_FILE
- if test 3504 -ne `wc -c <'tec-v3/tec.out.1'`; then
- echo shar: \"'tec-v3/tec.out.1'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/tec.out.1'
- fi
- if test -f 'tec-v3/tec.out.2' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/tec.out.2'\"
- else
- echo shar: Extracting \"'tec-v3/tec.out.2'\" \(3504 characters\)
- sed "s/^X//" >'tec-v3/tec.out.2' <<'END_OF_FILE'
- X000000000000000000000000000000000000000000000000011111111111221000000000
- X000000000000000000000000000000000000000000000000001111111111222000000000
- X000000000000000000000000000011000000000000000000001111111111122100000000
- X000000000000000000000000011111110000000000000000000111111111111100000000
- X000000000000000000000000111111111100000000000000000111111111111100000000
- X000000000000000000000000011111111100000000000000000011111111111001100000
- X000000000000000000110000000011111100000000000000000011111111111011110000
- X000000000000000001110000000001111100000000000000000001111111211121111000
- X000000000000000001110110000000011110000000000000000001111111221121111000
- X000000000000000001111100000000000111000000000000000000111111221121111000
- X000000000000000001111110000000000111000001000000000000111111221121111000
- X000000000000000001111111110000000111000001000000000000011111221111111000
- X000000000000000001111111111000001111000001000000000000001111211112111000
- X000000000000000001211111111100011111000001000000000000001111221112111000
- X000000000000000001111111111110111111000001100000000000000111122112111000
- X000000000000000001111111111111111111000001110000000000000111122112111000
- X000000000000000001111111111111111111000001111000000000000011122112111000
- X000000000000000001111111111111111111000001111000000000000011112111210000
- X000000000000000000111111111111111111000001111100000000000001112211110000
- X000000000000000000111111111111111111000001111110000000000000112211110000
- X000000000000000000111111111111111111000001111110000000000000011221110000
- X000000000000000000111111111111111111000001111111000000000000001111100000
- X000000000000000000121111111111111111000001111111000000000000000111000000
- X000000000000000000011111111111111111000001111111000000000000000010000000
- X000000000000000000001111111111111111000001111111100000000000000000000000
- X000000000000000000000000121111111111000001111111110000000000000000000000
- X000000000000000000000000111111111110000001111111111000000000000000000000
- X000000000000000000000000121111111100000001111111111100000000000000000000
- X000000000000000000000000011111111000000011111111111110000000000000000000
- X000000000000000000000000001111111000000011111111111110000000000000000000
- X000000000000000011111100000111111000000011111111111111000000000000000000
- X000000000000000112222110000000011000000011111111111111000000000000000000
- X000000000001011222222210000000001000000011111111111111100000000000000000
- X000000000011112221112211000000000000000001111111111111110000000000000000
- X000000000012222111111121000000000000000001111111111111110000000000000000
- X000000000012211111111121110000000000000001111111111111100000000000000000
- X000000000011111111111112211111000000000001111111111111000000000000000000
- X000000000001111111111112222221110000000001111111111110000000000000000000
- X000000000011111111111112222222221100000000000000000000000000000000000000
- X000000000011111111112222222222222110000000000000000000000000000000000000
- X000000000011111111112222222222222210000000000000000000000000000000000000
- X000000000001111001111111111111111110000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- END_OF_FILE
- if test 3504 -ne `wc -c <'tec-v3/tec.out.2'`; then
- echo shar: \"'tec-v3/tec.out.2'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/tec.out.2'
- fi
- if test -f 'tec-v3/tec.out.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/tec.out.3'\"
- else
- echo shar: Extracting \"'tec-v3/tec.out.3'\" \(3504 characters\)
- sed "s/^X//" >'tec-v3/tec.out.3' <<'END_OF_FILE'
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000001110000000000000000000011000000000000000000
- X000000000000000000000000000001101111111111111111111111000000000000000000
- X000000000000000000000000000000001111111111111111111111000000000000000000
- X000000000000000000000011000000000111111111111111111111000000000000000000
- X000000000000000000000011100000000001111111111111111111110000000000000000
- X000000000000000000000011111100000000011111111111111111110000000000000000
- X000000000000000000000011111100000000000111111111111111100000000000000000
- X000000000000000000000011111110000000000011111111111111100000000000000000
- X000000000000000000000011111111110000000001111111111110111111110000000000
- X000000000000000000000011111111111000000001111111111101111111111000000000
- X000000000000000000000011111111111110000000111111000001111111111110000000
- X000000000000000000000011111111111111000000011110000011111111111110000000
- X000000000000000000000011111111111110000000111110000111111111111000000000
- X000000000000000000000011111111111111100001111110001111111111110000000000
- X000000000000000000000011111111111111110011111111111111111111110000000000
- X000000000000000000000001111111111111111111111111111111111111111100000000
- X000000000000000000000001111111111111111111111111111111111111111110000000
- X000000000000000000000001111111111111111111111111111111111111111110000000
- X000000000000000000000001111111112221111111111111111111111111111110000000
- X000000000000000000000001111111112221111111111111111111111000010000000000
- X000000000000000000000000111111112211111111111111111111110000000000000000
- X000000000000000000000000000011122111111111111111111111111000000000000000
- X000000000000000000000000000111121111111111111111111111111100000000000000
- X000000000000000000000000001111111111111011111111111111111100000000000000
- X000000000000000000000000011112111111110011111111111111111100000000000000
- X000000000000000111111111111122111111110011111111111111111000000000000000
- X000000000000000111111111111111111111110011111111111111110000000000000000
- X000000000000000111111112222111111111110011111111111111000000000000000000
- X000000000000000111111222211111111111110011111111111111100000000000000000
- X000000000000000111111221111111111111111001111111111111110000000000000000
- X000000000000000111111111111111111111111101111111111111100000000000000000
- X000000000000000111111111111111111111111101111111111111000000000000000000
- X000000000000000111111111111111111111111001111111111110000000000000000000
- X000000000000000111111111111000111111100001111101101100000000000000000000
- X000000000000000111111111000000000000000000000000000000000000000000000000
- X000000000000000001111110000000000000000000000000000000000000000000000000
- X000000000000000000111000000000000000000000000000000000000000000000000000
- X000000000000000000010000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- X000000000000000000000000000000000000000000000000000000000000000000000000
- END_OF_FILE
- if test 3504 -ne `wc -c <'tec-v3/tec.out.3'`; then
- echo shar: \"'tec-v3/tec.out.3'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/tec.out.3'
- fi
- if test -f 'tec-v3/howtorun.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/howtorun.doc'\"
- else
- echo shar: Extracting \"'tec-v3/howtorun.doc'\" \(9224 characters\)
- sed "s/^X//" >'tec-v3/howtorun.doc' <<'END_OF_FILE'
- COMPILING AND RUNNING TEC ON THE AMIGA
- X
- Compile tec1.c, tec2.c, tec3.c and ami.c. I have Lattice C 4.0
- and I use lc1 -oram:, lc2 -ccdb -v. The -ccdb puts the entire
- executable into chip ram; this is overkill, but the custom chips have
- to be able to get to the graphics structures in ami.c. Then BLink the
- four .o files along with the startup code and the lcm, lc and amiga
- libraries (lcm has to be before lc, but you knew that).
- X
- Tec doesn't need any command line arguments, but if you wish to store
- snapshots you should redirect standard output to a file, for example
- X
- tec >ram:tec.out
- X
- XEach snapshot is about 32K of text.
- X
- When the program comes up, it opens a 5 bitplane 320 x 200 screen with one
- big window. If you need to see the Workbench screen again you can use
- left-amiga-m,n. After a second or two, a big green blob will pop up. This
- is the initial supercontinent. Every three seconds or so, another "step" will
- be computed and drawn.
- X
- Altitudes are represented by colors; from lowest to highest, these are:
- black (ocean), dark blue (deep continental shelf), bright blue (higher
- continental shelf), dark green (lowest abovewater elevation), bright green,
- dark red, bright red, purple, white, yellow. There are about 24 visibly
- different altitude ranges, since each color has several shades.
- X
- As time passes, you will see the supercontinent split up; red and purple
- mountains will appear on the leading edges of drifting continents; when
- continents slow down, reverse course, and collide, high purple and white
- mountains will appear. If you watch carefully, you can see erosion on
- mountains that are not growing; they turn dark red and then bright green.
- X
- At any time, you can click on the close window gadget to kill the program.
- It only checks the mouse once per update, so it may take the program a few
- seconds to notice you have killed it.
- X
- If you click the left mouse button anywhere but on the close gadget, the
- program will pause after the next update and write 450 lines of data to
- stdout. If you have not redirected stdout to a file, it takes about two
- minutes for it all to come out; redirected to ram:, it takes about 30
- seconds. The program obviously will not do anything else during this time.
- Typing ctrl-C will bring up a Lattice requester asking if you want to abort;
- I don't advise this, because the abort does not close the window and screen.
- X
- X
- COMPILING AND RUNNING TEC ON A UN*X PLATFORM
- X
- Type "cc -o tec tec?.c unix.c -lm" to create an executable called tec.
- Tec doesn't need any command line arguments and prints all its output
- to stdout. To do almost anything interesting, you will have to adjust
- the parameters, as explained in the file params.doc.
- X
- X
- COMPILING AND RUNNING TEC UNDER SUNVIEW
- X
- Type "cc -o tec tec?.c sun.c -lsuntool -lsunwindow -lpixrect -lm" to make
- an executable called tec. A canvas subwindow is opened; every second or so
- another step will be displayed. On the Sparcstation several steps are
- displayed per second. The colors displayed are identical to those
- used in the Amiga version. Use the Sunview menu to exit the program. I
- am using the simplest Sunview interface scheme, and you have to hold the
- mouse button down for a couple of seconds to get the menu. Currently it is
- not possible to tell the Sunview version of tec to print output; use the
- Un*x version for that.
- X
- X
- COMPILING AND RUNNING TEC ON AN IBM PC/XT/AT OR 100% COMPATIBLE (TURBO C 2.00+)
- X(This section by Peter Lind)
- X
- Suggested Compiler Configuration
- The following compiler options are recommended to yield the fastest execution
- speed. Any or all may be changed as the user sees fit. On 80x86 machines (as
- opposed to the 8088), enabling word-boundary alignment will increase speed.
- On 80186/80286 machines, enabling the extended instruction set will also yield
- a speed-up. If an 80x87 is available, enable generation of 80x87 code. Finally,
- for best results, disable all debugging-oriented options.
- X
- X Memory Model : Compact (or Large or Huge).
- X Optimization : Optimize for speed
- X Use of registers ON
- X Register optimization ON
- X Jump optimization ON
- X
- Option 1 -- Integrated Environment
- Create a file called TEC.PRJ containing the lines 'tec1.c', 'tec2.c',
- X'tec3.c', 'ibmpc.c'. Set the Project name to TEC.PRJ and press F9 to make.
- The resulting file will be called TEC.EXE. Ignore the warnings produced.
- X
- Option 2 -- Command Line Make
- Read through the comments in the make file TEC.MAK; the macro directory
- names may have to be changed to conform with your system; also, there are
- certain macros that can be changed to compile TEC for an 80186/80286
- and/or an 80x87.
- X
- Run the Turbo C MAKE utility with the command line: make -ftec.mak
- The included makefile TEC.MAK uses the command line options listed below;
- either of these may be changed to suit the user's preference:
- X -mc Compact memory model
- X -G Optimize for speed
- X -w- Suppress warnings
- X -a Align to word
- X
- A Note on Required Files (supplied with Turbo)
- X
- X i) Either (or both) .BGI files (CGA.BGI and EGAVGA.BGI) must reside in the
- X *current* DOS directory (where it is assumed TEC.EXE resides).
- X
- X ii) If TEC is to be run in EGA/VGA mode, TRIP.CHR should reside in the
- X *current* DOS directory.
- X
- X If TEC is to be run in CGA/MCGA mode, LITT.CHR should reside in the
- X *current* DOS directory.
- X
- X iii) If the programmer wants to execute TEC via the DOS search path, then
- X modifications will have to be made to IBMPC.C, and (sorry, but) the
- X programmer is on his/her own since this problem is not straightforward
- X and could be solved in a variety of ways (most simple of which would be
- X to place the *exact* DOS path in double quotes as the third parameter
- X to grafinit() in IBMPC.C).
- X
- X
- Running the Program
- X
- The IBM PC version of TEC will run under CGA, MCGA, EGA or VGA graphics,
- auto-detecting the graphics hardware and choosing the mode with highest
- resolution. Since CGA and MCGA hi-res modes provide only two colors (black
- and white), a rudimentary 3-D plotting facility is provided to take the
- place of the standard multi-colored plotting. In EGA or VGA, the user may
- switch between the multi-colored and 3-D modes as desired. The 3-D facility
- is rather sluggish, but produces interesting plots; it can be run in either
- X"fast" or "slow". In slow mode, each "pixel" of the plate tectonics is drawn
- as a 3-D block. In fast mode, all "pixels" in the same row with the same height
- are merged and plotted as a wide "slab". The fast mode is faster, but the plot
- produced does not look as good as that generated by the slow mode.
- X
- When TEC.EXE is run, the introductory credits panel will first be displayed;
- press any key to cause the program to continue. A window will then be drawn on
- the screen with a title bar along the top and a message line along the bottom.
- The program will display the message "Setting up..." while the initial data
- structure preparation is performed. Then, TEC will enter its main loop that
- repeatedly generates one "time step" and displays the map.
- X
- a) Thinking Phase: TEC displays the message "Thinking..." while generating the
- X next step. While TEC is "thinking", the user may press a key:
- X
- X ESC Abort to DOS when finished thinking
- X SPACE Pause after plotting until any key pressed
- X p or P Print (Generic, Text or Postscript)
- X g or G Change plotting style (Standard, Slow 3-D, Fast 3-D)
- X
- X TEC will respond to the key press when it finishes thinking.
- X
- b) Plotting Phase: When finished thinking, and provided that the user did not
- X abort the program, TEC will display the message "Plotting..." and begin
- X plotting the current step. In CGA/MCGA, the plotting is always monochromatic
- X simulated 3-D. In EGA/VGA, TEC displays different altitudes in different
- X colors. From lowest to highest, these are: black (ocean), dark blue (deep
- X continental shelf), light blue (higher continental shelf), dark green
- X (lowest abovewater elevation), light green, yellow, magenta, light magenta,
- X dark red, light red, brown, light gray, and white. There are 13 visibly
- X different altitude ranges.
- X
- X The following keys are recognized while plotting:
- X
- X ESC Abort to DOS immediately
- X CR Skip current plot (immediately start next thinking phase)
- X p or P Print (Generic, Text or Postscript) when done plotting
- X g or G Change plotting style (Standard, Slow 3D, Fast 3D)
- X
- X If `p' (or `P') is pressed, the print operation will start after the plot is
- X completed. Note that printing will not proceed unless stdout was redirected
- X on the command line, as in:
- X
- X TEC >TEC.OUT
- X
- X
- X The action that TEC takes when `g' (or `G') is pressed depends on the
- X graphics mode:
- X
- X (i) If TEC is running under CGA or MCGA, the user is able to switch
- X immediately between fast or slow 3-D plotting (but is unable to
- X switch to standard, color plotting).
- X
- X (ii) If TEC is running under EGA or VGA, the command is deferred
- X until the plot is finished (as the plot cannot be restarted).
- X
- END_OF_FILE
- if test 9224 -ne `wc -c <'tec-v3/howtorun.doc'`; then
- echo shar: \"'tec-v3/howtorun.doc'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/howtorun.doc'
- fi
- if test -f 'tec-v3/params.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/params.doc'\"
- else
- echo shar: Extracting \"'tec-v3/params.doc'\" \(5099 characters\)
- sed "s/^X//" >'tec-v3/params.doc' <<'END_OF_FILE'
- If you give tec a filename as a command line argument, it will read
- parameters from that file. If you hand it '-' as an argument, it will
- read them from stdin. For example, you could type "tec - < foo", or
- X"tec foo". The '-' option is handy for pipes.
- X
- The parameter file is optional; all of the parameters you can change
- have defaults. Thus, the parameter file need contain only the parameters
- you want to change. A parameter file looks like LISP; for example,
- to change the XSIZE parameter, the file would have the one line
- X
- X(XSIZE 40)
- X
- Parameters can also be vectors; for example
- X
- X(MOVERATE (1 1 1))
- X
- The parameters are either easy or hard. This rating concerns how much
- you have to know about the simulation to change the parameters. Easy
- ones just affect run time, resolution, and so on. Hard ones should
- only be changed if you understand the code pretty well.
- X
- XEasy parameters:
- DRAWMODE - 0 produces no output, 1 produces a long text file (default),
- X 2 produces a summary text file and 3 produces PostScript
- X grayscale drawings.
- DRAWEVERY - How many steps should be iterated for each output. Default 1,
- X but this produces an awful lot of text. Reasonable values
- X for non-interactive runs are 5 or 10. Supercontinents appear
- X every 25 steps or so.
- MAXSTEP - How many steps to run before terminating. Default 100.
- XXSIZE - Horizontal size of arrays. Default 90. To produce summaries
- X that fit on a normal page, I used 72.
- YSIZE - Vertical size of arrays. Default 90. To produce the summaries
- X included in tec.out.[1-3], I used 48.
- BLOBLEVEL - Indirectly related to size of initial supercontinent. I made
- X some 4000 blobs with different values of BLOBLEVEL to come up
- X with this empirical relationship: the average diameter of the
- X supercontinent is 83 - (0.625 * BLOBLEVEL). The blob is
- X clipped to the size of the world and can not exceed a
- X diameter of 64 anyway.
- X
- So to produce a text file with 10 pictures, you could use
- X
- X(DRAWMODE 2) (DRAWEVERY 10) (XSIZE 72) (YSIZE 48) (BLOBLEVEL 80)
- X
- To produce a 20-page PostScript output with a little more detail, use
- X
- X(DRAWMODE 3) (DRAWEVERY 5)
- X
- Hard Parameters:
- ZINIT - Initial altitude of supercontinent. Default 22.
- ZSUBSUME - Altitude added to leading edge of drifting plate. Default 16.
- ZCOAST - Sea level. Everything below this is under water. Default 16.
- ZSHELF - Minimum altitude for continental shelf. Default 8.
- ZMOUNTAIN - Used in DRAWMODE 2; altitude above which a square is counted
- X as mountain instead of land. Default 48.
- MAXBUMP - If two plates overlap on more than this number of squares,
- X the plates must be merged together. Default 50.
- BUMPTOL - If the relative velocity of two touching plates is less than this
- X value, the plates will be merged together. Default 50.
- MOVERATE - A vector of real numbers describing the rate at which plates
- X move apart, slow down, and then drift back together. Each
- X plate has an age, measured in steps from its creation. The age
- X is used as an offset into the vector. The result is a real
- X between -1.0 and +1.0 which is multiplied by the plate's original
- X movement vector. The default vector is
- X
- X (1.0 1.0 1.0 0.7 0.4 0.1 -0.2 -0.5 -0.8 -1.0)
- X
- X It can be interpreted this way. The first three steps a plate is
- X in motion, it moves at its normal velocity. During the 4-6
- X steps, it slows down. During the 7-10 steps, it moves the
- X opposite way from the way it started, at increasing speeds.
- X Thereafter, it keeps moving at its final velocity.
- RIFTPCT - Percent chance that a rift will occur in a given step. Default 40.
- MAXCTRTRY - The number of tries the rift routine will make to find an
- X acceptable place to start a rift. Default 50.
- RIFTDIST - The minimum allowable distance between a proposed rift center
- X and the nearest coast. Default 5.
- DOERODE - Whether or not to compute erosion. Default 1; if 0, the program
- X will run about twice as fast but will generate way too many
- X mountains, since the only thing that gets rid of mountains
- X is erosion.
- XERODERND - The rounding factor used in erosion. Default 4. As this
- X parameter goes from 0 to 7, erosion occurs faster.
- BENDEVERY - Each time a rift grows by this many squares, it is allowed to
- X bend a little bit. Default 6.
- BENDBY - When a rift bends, it bends by a random angle in the range
- X -BENDBY ... +BENDBY multiplied by pi/2000. Default value is 100.
- X If BENDBY is too high or BENDEVERY is too low, very curvy rifts
- X will be generated, with unrealistic results.
- SPPEDBASE - The minimum speed at which new plates will travel. Default 200.
- SPEEDRNG - The actual speed at which a plate travels is SPEEDBASE +
- X rnd (SPEEDRNG). Default value is 300.
- END_OF_FILE
- if test 5099 -ne `wc -c <'tec-v3/params.doc'`; then
- echo shar: \"'tec-v3/params.doc'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/params.doc'
- fi
- if test -f 'tec-v3/technical.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/technical.doc'\"
- else
- echo shar: Extracting \"'tec-v3/technical.doc'\" \(10300 characters\)
- sed "s/^X//" >'tec-v3/technical.doc' <<'END_OF_FILE'
- I. MOTIVATION AND APPROACH
- X
- I wanted to write a program to generate maps of many imaginary worlds using
- a microcomputer. Fractal techniques produce unacceptably random-looking maps.
- In other related fields, people have used simplified models of physical
- processes and then tweaked the model parameters to give results that "looked
- right". Dole [1] simulated accretion of planets around stars. Hart [2]
- simulated the evolution of a planetary atmosphere. Forrester [3] simulated
- population dynamics for near-future Earth. My approach was to find a physical
- model for continent formation, and then write a program to implement that model.
- X
- Geologists have proposed [4] that several times in history, the continents
- of Earth have drifted together to form a single "supercontinent", which later
- broke apart. A recent paper [5] suggested a physical model for this
- X"supercontinent cycle", and I used that model for my program.
- X
- Their hypothesis runs like this. (Disclaimer - I don't know anything about
- geology except what I got from reading a few papers.) The Earth generates
- heat by radioactive decay; this heat is conducted away more slowly by
- continental crust than by oceanic crust. Heat accumulates under large
- continents, causing them to dome upwards and eventually break apart. After
- a certain amount of heat has escaped through the new ocean basin, the
- continental fragments are drawn back together by the subsiding basin.
- Over long periods of time, many oceans should open and close in the center
- of the land area, while the original superocean should remain about the same.
- X
- Any map of the Earth shows evidence to support this hypothesis. The Atlantic
- and Mediterranean oceans are fairly recent, while the Pacific could be
- considered the superocean. The Himalayas, the Pyrenees, and the Ukraine
- mountain ranges could have been formed by collisions between continental
- fragments. The "Ring of Fire" around the Pacific represents subduction zones
- where new mountains, such as the Rockies, are forming as the continents drift
- further apart. The older, lower Appalachian mountains might have been created
- during a collision between Europe and North America in the last supercontinent
- cycle.
- X
- X
- II. REPRESENTATION
- X
- One data structure well-suited for storing topographic maps is a simple
- two-dimensional array, where each array element represents the height
- of the terrain at that point. However, the Earth is spherical and a sphere
- can't be mapped onto a plane without some distortion. After trying many
- mapping methods, I came back to the simplest: I pretend Columbus was wrong,
- and the world really is flat. Since the continents in the physical model
- drift toward and away from some central point, it is reasonable, if the map
- is large enough, to simply throw away the land area that falls off the
- edge of the map. I used a simple square, flat surface with no "wraparound."
- X
- I could, and probably will at some point, write a couple of paragraphs about
- why doing plate movement on a sphere is so hard. All of the methods I
- tried required too much data storage for each point, or too much real
- number computation, or resulted in unacceptable distortion. The criterion
- I used was to place a small continent, say a 5 x 5 square, anywhere on
- the surface. It should be able to travel one great circle in any direction
- and remain undisturbed though the entire journey. The method should not
- require _any_ floating point computation once the initial velocity is
- computed since I want to do many iterations on a microcomputer.
- X
- A second representation issue is how to cause plates to drift apart and
- back together. Maintaining the detailed structure of the ocean basin is
- complicated; consider a circular landmass which splits along a diameter.
- The ocean basin structure here is clear, since the rift remains in place and
- the new basin extends out from it in both directions. Now suppose one of
- the semicircular fragments splits in half perpendicular to the first split.
- The motion of the landmasses can be computed easily, but the new rift must
- drift as well and the required motions in the basin seem self-contradictory.
- X
- I chose to ignore the ocean basin and concentrate on the landmasses. Thus,
- rifts are not recorded in any way and the ocean floor does not move. Since
- the basins are not simulated, some mechanism is needed to replace the physical
- mechanism of the sinking basin sucking the landmasses back together. This
- is done by a velocity scaling profile which is coded directly into the
- movement routine. The profile says that after a short time, forward motion
- of a landmass slows and then stops; after this point the landmass begins to
- move backwards towards its origin.
- X
- X
- III. ALGORITHM
- X
- The initial supercontinent is generated by a simple fractal algorithm; a
- fractal mountain is created by superimposing four two-dimensional fractal
- lines. The mountain is then turned into a binary blob, that is, everything
- above a certain altitude is declared to be land, and everything else becomes
- water. The blob is then "improved" by removing islands and internal oceans.
- This technique produces very irregular circular blobs of varying sizes.
- X
- The program then repeats a sequence of operations for each timestep. First,
- a rift may be generated, splitting some continent into pieces; new velocities
- are generated for the new landmasses. Second, the distance each landmass will
- move this timestep is determined by applying the velocity profile described
- above to the landmass velocity. Third, the landmasses are moved and mountains
- are built. Fourth, where the movement routine has caused landmasses to
- overlap, new velocities are computed for the overlapping landmasses, and they
- may be merged into a single landmass if they overlap sufficiently. Fifth, the
- entire topography is eroded; if a square is higher than the square next to
- it, the altitudes are made more equal. Finally, the screen is redrawn.
- X
- In step one, random coordinates are generated until a location is found
- which is at least five squares from any ocean. This location will be the
- center of a rift, which is represented as a randomly curving line. The
- distance requirement is there to ensure that if a rift occurs, it occurs
- on a fairly large continent where internal heat would accumulate. When
- the rift is drawn, it is allowed to bend randomly but is drawn using
- conventional digital line-drawing techniques (i.e. Bresenham's algorithm).
- The rift drawing routine terminates when the rift hits ocean. If the growing
- rift hits another landmass, which could occur if two landmasses were touching
- but had not yet merged, the rift is aborted since the result would be a very
- unnatural looking U-shaped continent.
- X
- Once the rift is created, a segmentation algorithm determines how
- many new landmasses were formed. There should only be two new landmasses,
- but splinters can be formed if the rift runs along a narrow peninsula or
- too close to a coast. The algorithm detects and erases such splinters.
- The landmasses are given an initial velocity which makes them drift directly
- away from the rift. The velocities are inversely dependent on the area
- of the landmass so that smaller masses move faster. After the initial
- velocities have been determined, the rift is erased.
- X
- The second and third steps are concerned with moving the landmasses. This
- is done with a slightly simpler version of Bresenham's algorithm. The velocity
- profile described in Section II is applied so that landmasses will drift
- apart at first, but will then slow down and come back together. Because a
- landmass can split up again, the process does not simply reassemble the
- original supercontinent when they drift back together.
- X
- Mountains are built under two conditions: where two landmasses collide, and
- where landmass subsumes ocean basin. Both conditions are detected and resolved
- in the movement routine. Movement is performed from a source array to a
- destination array. A loop steps over every square in the source array. If
- there is land in a square, its new position is computed based on what
- landmass the square belongs to. If there is ocean basin there in the source
- array, the square belongs to the leading edge of a landmass which is subsuming
- ocean basin. A constant is added to the height of the land in that square.
- If there is land there in the destination array, then the two landmasses are
- colliding. There is a collision array which records how many times each
- pair of landmasses collide in any given timestep, and the movement routine
- increments the appropriate element of this array for each collision.
- Mountains are built in this case by adding half the height of the lower
- terrain to the height of the higher terrain.
- X
- Step four uses the collision information provided by the movement routine
- to adjust the velocities of colliding landmasses and perhaps merge them.
- XFor each pair of colliding landmasses, the routine determines how "strong"
- the collision is this timestep. The velocities are adjusted, again in
- inverse proportion to the landmass areas, so that the continents begin
- to come to rest with respect to each other. If the relative velocity of
- the two landmasses, after adjustment, is small enough, then the masses
- are merged. This is the mechanism that reassembles the continental
- fragments into a supercontinent.
- X
- XErosion is the final, and most computation-intensive, step of the simulation.
- XEach pair of adjacent squares is considered exactly once. If either square
- is part of a landmass, erosion occurs. Some fraction of the difference between
- the two squares' altitudes is subtracted from the taller and added to the
- shorter. This is a very simple algorithm since it ignores many factors,
- but more detail would make the simulation even slower.
- X
- X
- IV. REFERENCES
- X
- X1. Dole, Stephen H., "Computer Simulation of the Formation of Planetary
- X Systems", Icarus 13 (1970), pp 494-508.
- X2. Hart, Michael H., ""The Evolution of the Atmosphere of the Earth", Icarus
- X 33 (1978), pp 23-39.
- X3. Forrester, J.W., World Dynamics, Wright-Allen Press (1973).
- X4. Wilson, J. Tuzo, "Continental Drift", Scientific American 208, 4 (April
- X 1963), pp 86-100.
- X5. Nance, R.D., Worsley, T.R., and Moody, J.B., "The Supercontinent Cycle",
- X Scientific American (July 1988), pp 72-79.
- END_OF_FILE
- if test 10300 -ne `wc -c <'tec-v3/technical.doc'`; then
- echo shar: \"'tec-v3/technical.doc'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/technical.doc'
- fi
- if test -f 'tec-v3/ami.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/ami.c'\"
- else
- echo shar: Extracting \"'tec-v3/ami.c'\" \(6077 characters\)
- sed "s/^X//" >'tec-v3/ami.c' <<'END_OF_FILE'
- X/* This program is Copyright (c) 1990 David Allen. It may be freely
- X distributed as long as you leave my name and copyright notice on it.
- X I'd really like your comments and feedback; send e-mail to
- X davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
- X Maynard, MA 01754. */
- X
- X
- X/* This file contains only functions which are specific to the Amiga. It
- X connects to the other source files via a small number of functions.
- X Main() is here. It calls init() and onestep(). The other source files
- X can call rnd(), draw() and panic() from this file; these are at the end
- X of the file. My purpose here is to make tec?.c machine
- X independent, with all the machine dependencies in this file. */
- X
- X
- X#include "const.h"
- X#include "var.h"
- X#include "exec/types.h"
- X#include "intuition/intuition.h"
- X#include "intuition/intuitionbase.h"
- X
- extern short step; /* Defined in tec1.c */
- extern unsigned char t[2][MAXX][MAXY]; /* Defined in tec1.c */
- extern unsigned long RangeSeed; /* Amiga random number seed */
- extern struct IntuitionBase *IntuitionBase;
- X
- struct GfxBase *GfxBase;
- struct RastPort *rp;
- struct ViewPort *vp;
- struct Window *w = NULL;
- struct Screen *screen;
- struct IntuiMessage *message;
- unsigned long class;
- unsigned short code;
- X
- X/* 32 colors - 0-3 are used by Intuition; black background, grey gadgets, */
- X/* white shadows, red highlighting. Then there are 5 shades of blue from */
- X/* dark to light, 5 of green, 5 of red, 5 of purple, 5 white, and 3 yellow. */
- X/* A 5-bitplane screen is required. */
- unsigned short colors [32] = {
- X 0x000, 0x888, 0xfff, 0x00f,
- X 0x007, 0x009, 0x00b, 0x00d, 0x00f,
- X 0x070, 0x090, 0x0b0, 0x0d0, 0x0f0,
- X 0x700, 0x900, 0xb00, 0xd00, 0xf00,
- X 0x707, 0x909, 0xb0b, 0xd0d, 0xf0f,
- X 0x777, 0x999, 0xbbb, 0xddd, 0xfff,
- X 0x099, 0x0bb, 0x0dd };
- X
- X/* Structures for a custom lores screen of 5 bitplanes with a 320x200 */
- X/* window; use left-amiga-n and left-amiga-m to get back to workbench screen */
- X
- struct NewScreen ns = { 0L, 0L, 320L, 200L, 5L, 0, 1,
- X NULL, CUSTOMSCREEN, NULL, (UBYTE *)0, NULL, NULL };
- X
- struct NewWindow nw = {
- X 0, 0, 320, 200, 0, 1, 0, 0, NULL, NULL,
- X (UBYTE *) NULL, NULL, NULL,
- X 0, 0, 320, 200, CUSTOMSCREEN };
- X
- X
- main (argc, argv) int argc; char **argv; {
- X unsigned long t[3];
- X
- X /* Initialize random number generator using milliseconds of datestamp */
- X DateStamp (t); RangeSeed = t[2];
- X
- X /* Initialize everything */
- X grafinit ();
- X init (*++argv);
- X
- X /* Call onestep () once per step; check for mouse clicks */
- X for (step=0; step<MAXSTEP; step++) {
- X checkmouse ();
- X onestep (); }
- X
- X /* Loop forever until user clicks close gadget - busy waiting, sorry! */
- X while (1 == 1) checkmouse (); }
- X
- X
- grafinit () {
- X /* This is a standard kind of setup function; open all the libraries, then
- X open the screen, then open the window. If any of the calls fail, free the
- X memory and return 0. The rastport variable is kept for the drawing
- X function and the colors are loaded. */
- X
- X GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
- X IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0L);
- X screen = (struct Screen *) OpenScreen (&ns);
- X if (screen == NULL) goto c2;
- X vp = &screen->ViewPort; nw.Screen = screen;
- X nw.Title = "Tectonics";
- X nw.Flags = SIMPLE_REFRESH | WINDOWCLOSE;
- X nw.IDCMPFlags = MOUSEBUTTONS | CLOSEWINDOW;
- X w = (struct Window *) OpenWindow (&nw);
- X if (w == NULL) goto c1;
- X
- X rp = w->RPort; SetDrMd (rp, 0);
- X LoadRGB4 (vp, colors, 32);
- X return (1);
- X
- X c1: if (w) CloseWindow (w);
- X c2: CloseScreen (screen);
- X CloseLibrary (IntuitionBase);
- X CloseLibrary (GfxBase);
- X return (0); }
- X
- X
- grafexit () {
- X /* Just close all the things that were opened, then exit(). */
- X CloseWindow (w);
- X CloseScreen (screen);
- X CloseLibrary (IntuitionBase);
- X CloseLibrary (GfxBase);
- X exit (0); }
- X
- X
- checkmouse () {
- X /* Standard event handler; loop through all the messages that have come in,
- X figure out whether they are clicks or gadget hits, and reply to them.
- X Outside the loop, act on the clicks. If the CLOSEWINDOW gadget was hit,
- X exit the program; if the left button was clicked anywhere, print out the
- X current values of t[src] using tecst () in tec1.c. */
- X
- X short mousecode = 0, i, j, k;
- X
- X while ((message=(struct IntuiMessage *)GetMsg(w->UserPort))!=NULL) {
- X class = message->Class; code = message->Code;
- X ReplyMsg (message);
- X if (code == SELECTDOWN) mousecode = 1;
- X if (class == CLOSEWINDOW) mousecode = -1; }
- X if (mousecode == -1) grafexit ();
- X if (mousecode == 1) tecst (step % 2, DRAWMODE); }
- X
- X
- rnd (top) short top; { return (RangeRand (top)); }
- X /* RangeRand is located in Amiga.lib */
- X
- X
- panic (s) char *s; { printf ("PANIC: %s\n", s); grafexit (0); }
- X /* Used when some fatal inconsistency is found in the database;
- X its function is to immediately free all graphics memory and exit. */
- X
- X
- draw (src) short src; {
- X /* Takes the array m[src] and draws it on the screen, in a hopefully
- X efficient way. The function tries to make long horizontal
- X patches that are all the same color. Then they can be rendered by a
- X graphics function that draws arbitrary rectangles quickly. */
- X
- X register short i, j, k, x;
- X
- X /* Erase the screen first by drawing a big black box */
- X SetAPen (rp, 0); RectFill (rp, 14, 10, 280, 189);
- X
- X /* For each scan line, start at the left edge */
- X for (j=0, i=0; j<YSIZE; j++, i=0) {
- X
- X /* If the current square is not ocean, set x to its color */
- X top: if ((x = t[src][i][j] >> 2) > 1) {
- X
- X /* Go as far along to the right as you can in this color */
- X k = i+1; while (((t[src][k][j] >> 2) == x) && (k < XSIZE-1)) k++;
- X
- X /* Draw a short, wide rectangle */
- X if (x > 27) x = 27; SetAPen (rp, x+4);
- X RectFill (rp, 3*i + 14, 2*j + 10, 3*k + 13, 2*j + 11);
- X i = k-1; }
- X
- X /* If not at end of scanline, do more; else start next scanline */
- X if (i < XSIZE-1) { i++; goto top; } } }
- END_OF_FILE
- if test 6077 -ne `wc -c <'tec-v3/ami.c'`; then
- echo shar: \"'tec-v3/ami.c'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/ami.c'
- fi
- if test -f 'tec-v3/unix.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/unix.c'\"
- else
- echo shar: Extracting \"'tec-v3/unix.c'\" \(1223 characters\)
- sed "s/^X//" >'tec-v3/unix.c' <<'END_OF_FILE'
- X/* This program is Copyright (c) 1990 David Allen. It may be freely
- X distributed as long as you leave my name and copyright notice on it.
- X I'd really like your comments and feedback; send e-mail to
- X davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
- X Maynard, MA 01754. */
- X
- X
- X/* This file substitutes for ami.c. The function draw() is called by
- X onestep() once every DRAWEVERY steps, and it just calls tecst() in
- X tec1.c. Most of the functions in this file are dummies; see ami.c for
- X more details on what they were. */
- X
- X
- X#include "const.h"
- X#include "var.h"
- X#include <sys/types.h>
- X#include <sys/timeb.h>
- X
- extern short step;
- X
- X
- main (argc, argv) int argc; char **argv; { struct timeb t;
- X
- X /* Initialize random number generator */
- X ftime (&t); srandom ((int) ((t.time % 100000) + t.millitm));
- X
- X /* Run the program */
- X init (*++argv);
- X for (step=0; step<MAXSTEP; step++) onestep ();
- X exit (0); }
- X
- X
- rnd (top) short top; { return (random () % top); }
- X
- X
- panic (s) char *s; { printf ("PANIC: %s\n", s); exit (1); }
- X /* Used when some fatal inconsistency is found in the database;
- X its function is to just exit the program. */
- X
- X
- draw (src) short src; { tecst (src, DRAWMODE); }
- END_OF_FILE
- if test 1223 -ne `wc -c <'tec-v3/unix.c'`; then
- echo shar: \"'tec-v3/unix.c'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/unix.c'
- fi
- if test -f 'tec-v3/sun.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/sun.c'\"
- else
- echo shar: Extracting \"'tec-v3/sun.c'\" \(3564 characters\)
- sed "s/^X//" >'tec-v3/sun.c' <<'END_OF_FILE'
- X/* This program is Copyright (c) 1990 David Allen. It may be freely
- X distributed as long as you leave my name and copyright notice on it.
- X I'd really like your comments and feedback; send e-mail to
- X davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
- X Maynard, MA 01754. */
- X
- X
- X/* This file contains code to run tec under Un*x and Sunview. The
- X random number code is the same as that contained in unix.c; the
- X graphics code was inspired by the example code from Sun contained
- X in /usr/share/src/sun/suntool/examples/coloredit.c and in the
- X Sunview Programmer's Guide. I don't claim to understand it. The
- X code in draw() is similar to that in ami.c. */
- X
- X#include <suntool/sunview.h>
- X#include <suntool/canvas.h>
- X#include <sys/types.h>
- X#include <sys/timeb.h>
- X#include "const.h"
- X#include "var.h"
- X
- extern short step, phead; /* Defined in tec1.c */
- extern unsigned char t[2][MAXX][MAXY]; /* Defined in tec1.c */
- X
- X/* These arrays define similar colors to those in ami.c; the first two
- X are black, followed by two blues, four greens, four reds, four purples,
- X four greys, and a bunch of bright whites. */
- unsigned char red [] = {
- X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0,
- X 0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
- X 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
- unsigned char green [] = {
- X 0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00,
- X 0x00, 0x00, 0x00, 0x00, 0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0,
- X 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
- unsigned char blue [] = {
- X 0x00, 0x00, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- X 0x90, 0xb0, 0xd0, 0xf0, 0x90, 0xb0, 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00,
- X 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
- X
- X
- Pixwin *pw;
- struct rect tr = { 0, 0, MAXX * 6, MAXY * 6 };
- X
- X
- tecdestroy (c, s) Notify_client c; Destroy_status s; { step = MAXSTEP; }
- X/* A function called when the user tells Sunview to exit; it tells main()
- that its time is up, so main can exit after finishing the current step */
- X
- X
- main (argc, argv) int argc; char **argv; {
- X struct timeb t;
- X Frame base_frame;
- X Canvas canvas;
- X char cmsname[CMS_NAMESIZE];
- X
- X /* Initialize random number generator */
- X ftime (&t); srandom ((int) ((t.time % 100000) + t.millitm));
- X
- X /* Suntools-specific graphics setup */
- X base_frame = window_create (NULL, FRAME, FRAME_LABEL, "suntec",
- X WIN_WIDTH, MAXX * 6, WIN_HEIGHT, MAXY*6, 0);
- X canvas = window_create (base_frame, CANVAS, WIN_WIDTH,
- X MAXX * 6, WIN_HEIGHT, MAXY * 6, 0);
- X pw = (Pixwin *) canvas_pixwin (canvas);
- X sprintf (cmsname, "suntec%D", getpid());
- X pw_setcmsname (pw, cmsname);
- X pw_putcolormap (pw, 0, 32, red, green, blue);
- X notify_interpose_destroy_func (base_frame, tecdestroy);
- X window_set (base_frame, WIN_SHOW, TRUE, 0);
- X
- X /* Run the program, checking with Sunview after each step */
- X init (*++argv);
- X for (step=0; step<MAXSTEP; step++) { onestep (); notify_dispatch (); }
- X exit (0); }
- X
- X
- rnd (top) short top; { return (random () % top); }
- X
- X
- panic (s) char *s; { printf ("PANIC: %s\n", s); exit (1); }
- X
- X
- draw (src) short src; {
- X register short i, j, k, x;
- X
- X pw_lock (pw, &tr);
- X for (j=0, i=0; j<YSIZE; j++, i=0) {
- X top: x = t[src][i][j] >> 2;
- X k = i+1; while (((t[src][k][j] >> 2) == x) && (k < XSIZE-1)) k++;
- X pw_rop (pw, i*6, j*6, (k-i)*6, 6, PIX_SRC | PIX_COLOR (x), NULL, 0, 0);
- X i = k-1;
- X if (i < XSIZE-1) { i++; goto top; } }
- X pw_unlock (pw); }
- END_OF_FILE
- if test 3564 -ne `wc -c <'tec-v3/sun.c'`; then
- echo shar: \"'tec-v3/sun.c'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/sun.c'
- fi
- if test -f 'tec-v3/const.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/const.h'\"
- else
- echo shar: Extracting \"'tec-v3/const.h'\" \(515 characters\)
- sed "s/^X//" >'tec-v3/const.h' <<'END_OF_FILE'
- X/* This file contains some defines for maximum array dimensions, as well
- as the one structure definition needed and some miscellaneous declarations */
- X
- X#define MAXX 90
- X#define MAXY 90
- X#define MAXSPLINTER 10
- X#define MAXFRAG 100
- X#define MAXPLATE 40
- X#define REALSCALE 100
- X#define DRAWMODE_NONE 0
- X#define DRAWMODE_GENERIC 1
- X#define DRAWMODE_TEXT 2
- X#define DRAWMODE_GRAY 3
- X
- X#define ABS(xx) ((xx < 0) ? -xx: xx)
- X
- extern double cos(), sin(), sqrt();
- X
- struct plate { short dx, dy, odx, ody, rx, ry, age, area, id, next; };
- END_OF_FILE
- if test 515 -ne `wc -c <'tec-v3/const.h'`; then
- echo shar: \"'tec-v3/const.h'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/const.h'
- fi
- if test -f 'tec-v3/tec3.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tec-v3/tec3.c'\"
- else
- echo shar: Extracting \"'tec-v3/tec3.c'\" \(7136 characters\)
- sed "s/^X//" >'tec-v3/tec3.c' <<'END_OF_FILE'
- X/* This program is Copyright (c) 1990 David Allen. It may be freely
- X distributed as long as you leave my name and copyright notice on it.
- X I'd really like your comments and feedback; send e-mail to
- X davea@vlsi.ll.mit.edu, or send us-mail to David Allen, 10 O'Moore Ave,
- X Maynard, MA 01754. */
- X
- X/* This file contains the function getparams(), which reads parameters
- X from an input file. The default values for all of the parameters are
- X set here as well. */
- X
- X#include "const.h"
- X
- X/* These are all of the adjustable parameters; they are completely
- X described in the file params.doc. */
- X
- long XSIZE = 90, YSIZE = 90, MAXSTEP = 100;
- long MAXBUMP = 50, BUMPTOL = 50;
- long DRAWEVERY = 1, BLOBLEVEL = 64, DRAWMODE = DRAWMODE_GENERIC;
- long ZINIT = 22, ZSUBSUME = 16, ZCOAST = 16;
- long ZSHELF = 8, ZMOUNTAIN = 48;
- long RIFTPCT = 40, DOERODE = 1, ERODERND = 4;
- long MAXCTRTRY = 50, RIFTDIST = 5, BENDEVERY = 6;
- long BENDBY = 50, SPEEDRNG = 300, SPEEDBASE = 200;
- X
- double MR [] = { 1.0,1.0,1.0,0.7,0.4,0.1,-0.2,-0.5,-0.8,-1.0 };
- long MAXLIFE = 10; /* Length of MR vector */
- X
- X
- X#include <stdio.h>
- XFILE *fp;
- X
- X/* The input is handled by one function, gettoken, which returns one
- X of the following codes each time it is called. */
- X#define TOK_EOF 0
- X#define TOK_OPEN 1
- X#define TOK_CLOSE 2
- X#define TOK_WORD 3
- X
- short linecount = 1; /* So error messages can refer to a line number */
- char getbuf[256]; /* Storage for each token as it is being read */
- X
- X/* A shorthand for string comparison */
- X#define CMP(x) (!strcmp (getbuf, x))
- X
- extern float atof ();
- X
- X
- getparams (s) char *s; {
- X /* This function is called by init() with one parameter, a string which
- X comes directly off the command line. If the string is null, getparams()
- X is never called; otherwise, a "-" means standard input, while any other
- X text is treated as a filename and handed to fopen(). If the file doesn't
- X exist the program exits via panic(). Once the file is open, the function
- X expects to find paren-delimited pairs of (name value). Value could be
- X a vector, like (name (val1 val2)). After a name is found, there is
- X a very simple test, one string comparison per adjustable parameter,
- X to see if the name is recognized. If unrecognized, the program panics.
- X If it is a recognized name, the appropriate parsing function, with the
- X appropriate parameters, is called. There are three parsing functions,
- X getdim(), getlng(), and getdvec(). */
- X
- X short x, i, j;
- X
- X if (!strcmp (s, "-")) fp = stdin;
- X else { fp = fopen (s, "r"); if (!fp) panic ("Can't find input file"); }
- X
- X while ((x = gettoken (getbuf)) != TOK_EOF) {
- X if (x != TOK_OPEN) geterr ("expected open paren");
- X if (gettoken (getbuf) != TOK_WORD) geterr ("expected parameter name");
- X if CMP ("XSIZE") getdim (&XSIZE);
- X else if CMP ("YSIZE") getdim (&YSIZE);
- X else if CMP ("MOVERATE") getdvec (&MAXLIFE, MR);
- X else if CMP ("MAXSTEP") getlng (&MAXSTEP);
- X else if CMP ("MAXBUMP") getlng (&MAXBUMP);
- X else if CMP ("BUMPTOL") getlng (&BUMPTOL);
- X else if CMP ("DRAWEVERY") getlng (&DRAWEVERY);
- X else if CMP ("DRAWMODE") getlng (&DRAWMODE);
- X else if CMP ("BLOBLEVEL") getlng (&BLOBLEVEL);
- X else if CMP ("ZINIT") getlng (&ZINIT);
- X else if CMP ("ZSUBSUME") getlng (&ZSUBSUME);
- X else if CMP ("ZCOAST") getlng (&ZCOAST);
- X else if CMP ("ZSHELF") getlng (&ZSHELF);
- X else if CMP ("ZMOUNTAIN") getlng (&ZMOUNTAIN);
- X else if CMP ("RIFTPCT") getlng (&RIFTPCT);
- X else if CMP ("DOERODE") getlng (&DOERODE);
- X else if CMP ("ERODERND") getlng (&ERODERND);
- X else if CMP ("MAXCTRTRY") getlng (&MAXCTRTRY);
- X else if CMP ("RIFTDIST") getlng (&RIFTDIST);
- X else if CMP ("BENDEVERY") getlng (&BENDEVERY);
- X else if CMP ("BENDBY") getlng (&BENDBY);
- X else if CMP ("SPEEDBASE") getlng (&SPEEDBASE);
- X else if CMP ("SPEEDRNG") getlng (&SPEEDRNG);
- X else geterr ("unknown parameter name");
- X if (gettoken (getbuf) != TOK_CLOSE) geterr ("expected close paren"); } }
- X
- X
- gettoken (s) char *s; {
- X /* This is the only function which actually reads from the file. It
- X maintains a one-character unget buffer. It ignores initial whitespace,
- X but counts newlines to maintain an accurate linecount. Open or close
- X parentheses count as tokens, and so does any amount of text with no
- X whitespace or parens. The return code indicates whether end of file,
- X open paren, close paren, or a word were found. If a word was found, it
- X is copied into the string pointed to by s. When a word is found, the
- X character which terminated the word (whitespace, EOF or paren) is put
- X into the unget buffer to be read the next time gettoken() is called. */
- X
- X static char buf = 0; char c;
- X
- X white: if (buf) { c = buf; buf = 0; } else c = getc (fp);
- X switch (c) {
- X case '\n': linecount++;
- X case '\t':
- X case ' ' : goto white; break;
- X case EOF : return (TOK_EOF); break;
- X case '(' : return (TOK_OPEN); break;
- X case ')' : return (TOK_CLOSE); break; }
- X text: if ((c==' ')||(c=='\t')||(c=='\n')||(c=='(')||(c==')')||(c==EOF)) {
- X buf = c; *s = 0; return (TOK_WORD); }
- X else { *s++ = c; c = getc (fp); goto text; } }
- X
- X
- geterr (s) char *s; {
- X /* Calls machine-specific panic() with nicely formatted message */
- X sprintf (getbuf, "Parameter error: %s in line %d", s, linecount);
- X panic (getbuf); }
- X
- X
- getlng (x) long *x; {
- X /* Called after reading a name associated with a single long,
- X this function just reads a long from the input file and uses atoi()
- X to convert it into a long, stored at the address passed in. Note
- X that any text, including a string or a real, will be read; no type
- X checking is performed. */
- X
- X if (gettoken (getbuf) != TOK_WORD) geterr ("expected long");
- X *x = atoi (getbuf); }
- X
- X
- getdim (x) long *x; {
- X /* Called right after reading a name associated with an array bound,
- X this function reads one long from the input file; if the value is
- X greater than the default value assigned above, the user is trying
- X to exceed a compiled-in limit. That's an error. */
- X
- X long y;
- X
- X if (gettoken (getbuf) != TOK_WORD) geterr ("expected long");
- X y = atoi (getbuf);
- X if (y > *x) geterr ("dimension exceeds reserved space");
- X *x = y; }
- X
- X
- getdvec (dim, v) long *dim; double *v; {
- X /* Called right after reading a name associated with a one-dimensional
- X array of doubles, this function expects to find a list of doubles
- X starting with an open paren and ended by a closing paren. The parameter
- X dim contains the compiled-in array limit; if the input file contains
- X more than this number of entries, the function complains. No type checking
- X is done; atof() is used to convert any text to a double. On exit, the
- X dimension is set to the correct value. */
- X
- X short x; long i = 0;
- X
- X if (gettoken (getbuf) != TOK_OPEN)
- X geterr ("expected open paren");
- X while ((x = gettoken (getbuf)) == TOK_WORD) {
- X if (i == *dim) geterr ("vector is too long");
- X v[i++] = atof (getbuf); }
- X if (x != TOK_CLOSE) geterr ("expected close paren");
- X *dim = i; }
- END_OF_FILE
- if test 7136 -ne `wc -c <'tec-v3/tec3.c'`; then
- echo shar: \"'tec-v3/tec3.c'\" unpacked with wrong size!
- fi
- # end of 'tec-v3/tec3.c'
- fi
- echo shar: End of shell archive.
- exit 0
-
-