Treebeard's Homepage : Treebeard's BASIC Vault

## Conditions

No conditons, no promises. Programs and source code from Treebeard's BASIC Vault are yours to use and modify as you will, but they are offered as freeware with no warranty whatsoever. Give me credit, but do not distribute any changes under my name, or attribute such changes to me in any way. You're on your own!

Send comments and fixes to: Treebeard aka Marc Kummel (mkummel@rain.org).

There's something new in Treebeard's BASIC Vault!

## CHORD

This is a small program that draws all the chords between up to about 180 points around a circle. By default it colors the lines according to their length, which generates attractive mandalas. The trace function shows that it is always possible for any odd number of points to draw all the chords in string art fashion with a single line that ends where it began.

Last update: 13 Nov 2002

## BIGFAC

BIGFAC is a small BASIC program I wrote to find the factorial of big numbers up to 10,000,000! and factor the result. 10000000! is 1x2x3x...x10000000, a truly huge number of 65+ million digits! BIGFAC uses a disk file to store working results so it's not limited by string space. It does 100! in no time at all, but it takes about an hour to figure the 35,660 digits of 10,000 factorial. It's pretty fast since it does all the arithematic in base 10,000,000. It uses the hard drive to store intermediate results, so there's no limit on size, but I don't like the way it thrashes my hard drive when working with big numbers.

Last update: 18 Feb 2000

## BIGNUM

BIGNUM is a DOS BASIC program that features a large collection of big number arithmetic routines and number theoretical functions written in native BASIC with string operations. It's an engaging task to work out these algorithms in BASIC, since we know them so well on paper. My aim is to minimize string space; then speed. This is not quite arbitrary precision since numbers, work, and the answer must fit in BASIC string space, 64K+ with PDS far strings, much less with QBasic. It's limited by string space and time, but not precision. This code became the core of BNC.

Last update: 28 Sep 1997

## BNC

BNC (aka BigNum Cruncher) is a 16-bit WINDOWS calculator program built around a homebrew library of big number arithmetic routines written with Visual Basic 3.0 under Win31. It features a large set of arbitrary precision decimal arithmetic procedures written in native BASIC with string operations. It can accurately crunch numbers up to 64K digits, given "world enough and time". BNC is a useful calculator with many features, including expression evaluation, a BASIC-like scripting language, and the unique ability to play big numbers digit by digit as realtime MIDI sound events for Pythagorean algorithmic composition experiments. Win 3.1. Requires VBRUN300.DLL and a few other common DLLs that you probably have.

Last update: 28 Sep 1997

## CHOP

CHOP is an old DOS BASIC program from the Vault that draws mathematical waves and allows you to visualize wave interactions in a two dimensional plane. You can make sequences of waves and play them back as movies. I haven't figured out how to do reflections yet. Nice 3D graphics.

Last update: 28 Sep 1997

## CHORD

This is a small program that draws all the chords between up to about 180 points around a circle. By default it colors the lines according to their length, which generates attractive mandalas. The trace function shows that it is always possible for any odd number of points to draw all the chords in string art fashion with a single line that ends where it began.

Last update: 13 Nov 2002

## CLEO

CLEO is a DOS BASIC program that works with sound samples using a Sound Baster sound card. CLEO does things that shouldn't be possible in BASIC, including realtime FFT frequency analysis, and playing samples on a MIDI keyboard, varying the playback rate to follow your playing. It's a powerful experience to literally play John Coltrane on a keyboard! Requires Sound Blaster compatible sound card, and can use an external MIDI keyboard.

Last update: 28 Sep 1997

## CURVES

CURVES is a DOS BASIC program that draws mathematical curves of various types and animates them with unique graphic machines. It is an anthology of several small programs I've written over the years with a common interface. Six different animations are currently implemented, including a graphic Spirograph! This is my current project, so watch out for updates.

Last update: 28 Sep 1997

## ECLIPSE

ECLIPSE is a small BASIC program that predicts solar and lunar eclipses. I pulled this code from my much more ambitious TBC program that I wrote a few years ago. It's a kludge that does some things the hard way because the original program did so much more. At least it isolates the working routines for eclipse prediction. Sometime I'd like to add code to draw a picture of each eclipse event.

Last update: 6 Feb 2000

## EGG

EGG is a DOS BASIC program to draw EGGS. I always start the school year in my Science class at Dunn Middle School with an "Opener" topic for a few weeks, and eggs are a favorite. Nothing is more familiar than an egg, but there is much about an egg to wonder at, including its shape. One of my favorite assignments is to show the kids how to draw an ellipse using the classic string and two nails technique. Then I ask them to modify the technique to draw a proper egg that is bigger at one end than the other. The trick is to use multiple loops of string around the nails. I don't help much, and I don't show them this program until they've been working for a while.

Last update: 2 Nov 1997

## EVAL

EVAL is a DOS BASIC math expression evaluator with advanced functions, variables, and a QBasic-like scripting language. Type 2*(3+4) and get 14. It includes a Tiny BASIC written in BASIC! This code became part of BNC.

Last update: 28 Sep 1997

## FRI13

FRI13 is a small program I wrote to explore the distribution of Friday the 13ths over the years so that I could answer the Friday, November 13 stumper on my Stumper Page.
Today is Friday the 13th! Why is this particular day considered unlucky, and just how uncommon is it? Are there years with no Friday on the 13th? Can there be two in a row in successive months? What's the most there can be in a single year?
Using this program, you will find that every year has at least one Friday the 13th and at most three. You will also find that the 13th of the month is *more likely* to fall on a Friday than any other day of the week over any 400 year period after 1752, when the Gregorian Calendar was established in the US.

Last update: 5 Dec 1998

## HMAGIC

Here are two small Basic programs I wrote so that I could answer the Holiday Magic stumper on my Stumper Page:

 Place all the numbers 1 to 12 on the pattern, with one number on each character, so they add up to 26 in these seven different ways: each of the two center columns (\$@@\$) each of the two center rows (#@@#) the four \$ together the four # together the four @ together ``` \$ \$ # @ @ # # @ @ # \$ \$ ```

PARTITN.BAS is a snippet to solve a problem that arises with this stumper and other magic squares: What are all the ways in which m different numbers (p or less) can add up to n, without regard to order? HMAGIC.BAS uses the results to solve the stumper.

Last update: 10 Jan 1999

## KEY

KEY is a multi-language package to build a plant database for Web access. A DOS BASIC program makes a database with separate definition and data files, and lets you add items and run queries to test it. Separate HTML and CGI PERL scripts are included to search the database and make it work on the Web. So far I've only tested this by running my own HTTPD server on my home computer. Works fine. Details on the project, including my method for developing PERL CGI scripts without CGI access, are available at my flora.

Last update: 28 Sep 1997

## LIFE-ETC

LIFE-ETC is a DOS BASIC program that runs a dozen-plus different cellular automata, including the classic Life, all with a shared interface. It's slick, but slow, probably as fast as can be in BASIC. It has an excellent screen editor and many other goodies, and it's very easy to use.

Last update: 28 Sep 1997

## LIGHTSHO

LIGHTSHO is a DOS BASIC program that reads sound input to a SoundBlaster and makes a simple realtime lightshow based on the frequency content. It does a realtime FFT in Basic! This makes great displays from CD or radio or an electric guitar if it works for you. I used some of this code in my CLEO program. Requires Sound Blaster compatible sound card.

Last update: 28 Sep 1997

## MIDTXT

MIDTXT is a DOS BASIC program that reads Standard MIDI Files (SMF). These are the usual .MID files used by Windows and most sequencers. MIDTXT will show MIDI files in a text form with comments that can be studied or printed, and it will prepare a comprehensive report about the contents. It can also play .MID files on a Roland compatible MPU MIDI controller. It works with SMF type 0 and type 1 files, but not type 2. Sorry, SoundBlaster cards are NOT supported for MIDI output, but MIDTXT is still a useful utility without MIDI play.

Last update: 28 Sep 1997

## MSQ

MSQ is a DOS BASIC program that combines my interests in math and music to do Algorithmic Composition with MIDI. MSQ can take various mathematical functions (formulas, fractals, various random distributions, etc) and map them to MIDI notes and play them on attached synthesizers. It has enough track editing and recording functions to qualify as a full-on sequencer, and it's written in BASIC!. Requires a Roland compatible MPU MIDI controller.

Last update: 28 Sep 1997

## NPF

NPF is a DOS BASIC program frame. I've always had a PROGRAM FRAME, a homemade set of routines to handle menus and windows and other common programming chores. NPF (New Program Frame) is the current incarnation. It (and previous versions) is the shared interface for several of my programs in the Vault. Using NPF, I can start a new program that works right off with all support features, and then concentrate on my current problem. NPF is a demo, and a nearly blank program frame ready for use. NPF includes source code needed by CHOP, CURVES, TREE, and others of my programs, so you need this (or NPFLIB) if you want to use the other source code.

Last update: 28 Sep 1997

## NPFLIB

NPFLIB contains common source code modules required by several of the DOS programs available at Treebeard's BASIC Vault. These modules provide support for VGA mouse, menu, and window functions, EMS memory management, use of Windows bitmapped fonts, and more. Simply copy these files into a program directory along with other program source files and use XQB.BAT to start BASIC with the right options. NPFLIB uses a small library of assembly routines, but it is mostly written in BASIC, so it's easy to customize. If you don't like it, make your own!

Last update: 28 Sep 1997

## ODOMETER

ODOMETER is a small BASIC program I wrote to solve a tricky puzzle on my Stumper page. My car has two odometers that measure mileage. There's a six-digit counter that measures total miles, and a four-digit trip odometer that I can reset with a button. Given a starting mileage, when should I next reset the trip odometer so that all digits will be different as soon as possible?

Last update: 7 May 2000

## ORBIT

ORBIT is a DOS BASIC program that demonstrates star cluster dynamics with a simple n-body gravity simulator. ORBIT shows how complex dynamics arise from simple interactions that are repeated over time. I find it fascinating how so much of modern Chaos and Complexity theory come right from the classic Newtonian models of pendulums and solar system dynamics. The long term stability of the solar system is *still* an open question!

Last update: 28 Sep 1997

## PART2K

PART2K is a DOS BASIC program to find partitions of a number n into all the integer parts that add up to that sum, with the optional constraints that all partitions have just m parts, that all parts are unique, and that all parts be <= p. It computes P(n), Q(n), P(n,m), and Q(n,m). I wrote this program to solve a problem that arises with with magic squares and other recreational math stumpers: what are all the ways in which m different numbers can add up to n, without regard to order? Partitioning is a bit like factoring in that it decomposes a number, but it uses addition rather than multiplication. This was a fun programming challenge that uses recursive functions.

Last update: 9 Jan 2000

## PARTY

PARTY is a DOS BASIC party simulator. A group of guests with well-defined likes and dislikes is invited and allowed to interact, and their interactions show some surprising complex dynamics.. This is ancient code from the Vault circa 1987-8, inspired by A.K. Dewdney's Computer Recreations column in Scientific American, Sep 1987. It runs fine in QBasic.

Last update: 28 Sep 1997

## PICCAT

PICCAT is a small program I wrote to solve a problem. I bought an Olympus 320L digital camera this summer to take photos of local plants for my flora website. I love it! But after a month and a half, I've filled five Zip disks with over 2500 images and 500 MB of files. The problem is to find anything. PICCAT is a small DOS image catalog and index program that solves this problem.

Last update: 2 Aug 1998

## POKER

POKER is a DOS BASIC program that deals random poker games and keeps track of the statistics for different hands. It also allows you to play straight 5 card draw poker with 3 other imaginary players who have different poker personalities. POKER was inspired by a Dunn Middle School trip to the CIMI Environmental Education camp on Catalina Island in Fall 1993. In between snorkling and hiking, we had an ongoing poker game in the camping area, using wild cherry pits for chips. As the DMS science teacher and general math person, I felt it my duty to write this program to prove to the kids that a pair is not enough, and it's not worth drawing to an inside straight. (*After* winning more than my share, of course. That's definately a lesson in real world probability!) Then I started adding features in the usual way.

Last update: 28 Sep 1997

## QUEENS

Here are two simple BASIC programs to solve two classic chess stumpers that I recently (re)posed as stumpers at school and on my Stumper page: Chess queens can move in a straight line any distance up, down, across, or diagonally. Can you arrange eight peaceful queens on a chessboard so that no queen can attack any other? Eight peaceful queens will threaten every square on the board, but it's overkill. What's the smallest number of warrior queens that can threaten every square? Both programs use recursive functions to solve the general n by n problem for any size chessboard.

Last update: 18 Feb 2000

## ROBIN

ROBIN is a small BASIC program I wrote to create round robin schedules, eg for sports tournaments. It is a straight forward implementation of the "polygon algorithm". It works for any number of teams.

Last update: 18 Feb 2001

## SANTA

SANTA is a small BASIC program I wrote to solve an interesting stumper about Secret Santa gift exchanges. It has some useful algorithms for generating permutations.

Last update: 22 Feb 2002

## SOLSYS

If the Earth was a one-inch ball then what would the sun be and where? SOLSYS is a small BASIC program I wrote one night as my answer for a Dunn Middle School science assignment (I'm the teacher) to figure and build a true scale model of the solar system. You can enter a scale size for the Earth or for Pluto's orbit, and SOLSYS will figure the rest. It can automatically use common units like inches and meters. Simple, and useful. The message is that the solar system is a big empty place. Treasure it!

Last update: 6 Feb 2000

## TBC

TBC ("TreeBeard's Calendar"?) is is a DOS BASIC program that began as an assignment in my Dunn Middle School Science class to develop an algorithm to calculate how many seconds a person has been alive. This function is still included on the opening screen. But the program grew to become a general Calendar\Astronomy\Ephemeris\Almanac program. It has many features, including a growing database of events for every day of the year and the unique ability to play the positions of the planets as realtime MIDI sound. TBCAL.DAT is the plaintext database of daily events for TBC. I'll update it now and then and post it here. TBC requires a Roland compatible MPU MIDI controller for MIDI output, but works fine without it.

Last update: 28 Sep 1997

## TBD

TBD is Treebeard's Drum Circle, an ambitious pattern-based MIDI composer with many features. It is especially suited for composing MIDI drum patterns, but it can also work with pitched instruments. All editing changes can be heard immediately during play, so what you hear is what you get. You can record patterns directly from a keyboard or drum pad. Drum and melody patterns can be combined into complex jams, and then saved as standard MIDI files. There is special sysex support for Roland GS/SoundCanvas sound modules. TBD is a 16-bit Windows program written in Visual Basic 3. All source code is provided. Requires VBRUN300.DLL and MIDI drivers. This program is fun!

Last update: 8 May 1998

## TBM

TBM is a small 16-bit WINDOWS program for Visual Basic 3.0 in Win31. This was my way to learn how to control MIDI events in realtime for algo-comp purposes. TBM lets you noodle with your mouse on a virtual keyboard in a window, and use various sliders to massage the sound. It's fun! I reused most of this code in my BNC program that lets you play big numbers (to 32k digits) as MIDI. Win 3.1. Requires VBRUN300.DLL and a few other common DLLs that you probably have.

Last update: 28 Sep 1997

## TREE

TREE is a DOS BASIC program that makes trees of the botanical sort. These are not the usual L-Sys trees. My trees are based on a mathematical parameter set that defines branch angles, divergence, and other factors. Think of the parameter set as a chromosome, with each parameter value a gene. A tree is completely determined by its genes, so by mutating genes you can evolve new trees, and assess their fitness by measures of leaf surface area and efficiency. Trees can be saved as BMP files for use in Windows graphics programs. I love this program!

Last update: 28 Sep 1997

## WALK1D

WALK1D is a small DOS BASIC program that simulates random walks in one dimension. Flip a coin and turn left or right depending on the outcome. How long does it take to travel a certain distance? Realtime graphs show the walks and statistics.

Last update: 28 Sep 1997

## WALK2D

WALK2D is a small DOS BASIC program that simulates random walks in two dimensions. Roll a die and turn according to the outcome. How long does it take to travel a certain distance? Realtime graphs show the walks and statistics.

Last update: 28 Sep 1997

## XWORD

XWORD is an MSDOS BASIC program I wrote as my Dunn Middle School science fair project for spring 2000. I used it to make a crossword puzzle on my Stumpers webpage. It seems so simple. Take a list of words, say the first names of all Dunn Middle School students and staff, and arrange them all crossword-style in the smallest possible square grid. There are too many possibilities for even my fast computer program to check them all! That's my goal for this program, to make crossword grids from random lists of words. It works!

Last update: 21 May 2000

Treebeard's Basic Vault is part of  The BASIC Webring.