Drawbox is a lightweight, lighthearted package for
graphics programming in C++. It is especially designed for student
programmers, though others may find it useful. It is cross-platform,
supporting both Macintosh and Windows, so that students can use whatever
computer they have at school, and take their work home to whatever computer they
The programmer's interface is carefully designed
for quick-start, low-overhead programming. All you need to get started is
one #include and a main function, and the very first line of that function can
be a drawing command. No visible setup required. There is only one
window, and it does not need to be specified or named; it is implicit.
Drawbox is an open-source
effort. Programmers who want to add to the package itself are
welcomed to do so; please send fixes and improvements back to email@example.com
to be added to the main distribution. I would love to find someone
interested in doing a port to Linux.
This package is being maintained and improved in
an ongoing way. Work is in progress to make quick, frequent releases possible.
If you find bugs, please report them to: firstname.lastname@example.org.
If you teach programmers, or if you've been
wanting to do some lighthearted graphics programming yourself, download Drawbox
and give it a try!
(Macintosh .sea, 1.5 MB)
Download (Macintosh .hqx, 1.9 MB)
Download (Windows .EXE , 1.8 MB)
The archive you download actually contains the
code and projects for a dual build, Macintosh and Windows. See the Setup
directory for an easy way to remove what you don't need. If you actually want to
use the dual build, download and unpack on a Macintosh to preserve file type
I'm interested in having a small core of
highly-involved testers, who plan to use the package and interact with me a lot.
If you feel like being one of those, please speak
up! Or if you are a less involved user, but would like to be on the mailing
list for announcements of new releases, please speak
Why another graphics package?
How fondly I remember the days of my first
computer, and Apple II+. You could just sit down, write a few lines of Basic,
and it would start drawing graphics for you. But with the advent of Macintosh,
now followed by all other modern operating systems, the age of the GUI/window
system has come. A lot of research went into the original Macintosh interface
design, and it and its offspring have made programs much more user-friendly. But
not programmer-friendly. In Windows it takes upwards of 40 lines of code, just
to create a window that can interact with the system in a half-decent way. And
then you're ready to start doing graphics.
Drawbox is an attempt to bring back
programmer-friendly graphics. No setup required, except one simple #include, and
you're ready to go. I expect it to grow with time, to accommodate more of the
typical window-system things--but never compromising the ability to do simple
things simply, with very low overhead.
Another virtue, though less of a priority, is low
overhead in space. Drawbox can produce executables as small as 100K.
What's in the name?
When a professional enters upon the project of
programming in a new system, especially where graphics are involved, he is faced
with the vast and complex world of an operating system. It has historical
quirks, numerous system dependencies, and various data structures that the
programmer must initialize and use, although they are really only needful for
complex programs, not simple ones.
The beginning student must be protected from all
this. We need to build a "sandbox," a safe, confined environment in
which the student can enjoy graphics while being protected from the quirks and
the complexity. Drawbox is such a box, designed for students of beginning to
Drawbox Resources for Teachers
Marine Biology Case Study
Part 1: a fish swims back and forth randomly in
a tank, making a "bump" sound whenever it collides with the wall of
the tank. Statistics are reported as in the standard Case Study. An optional
advanced version shows several fish swimming at once, each at a different
depth and carrying out its own random walk.
Part 2: several fish, each with its own color
and number to identify it, swim randomly in a two-dimensional tank.
(Note: this exercise revealed a minor bug in the
display of numbers in the Windows version of Drawbox, which affects Part 2. It
impairs the visual quality but not the accuracy of the output. This will be
fixed after Christmas family visits are over!)
A very visual sorting algorithm
simulator, using colors as the sort keys. Includes most of the AP required
algorithms; you can also program more algorithms into it with a handy
object-oriented interface. SortWatcher page.
SortWatcher came out of my teaching work in an AP
Computer Science course, during the spring of 2000. It is a visualization based
on the use of colors (in their natural spectral order) to illustrate sort keys;
this has the result that as well as being beautiful, it very easily shows when
sorting is complete or nearly complete.
SortWatcher is flexible. You can specify the
number of array elements it will work on, and you can specify several aspects of
the speed of execution.
It is also extensible, designed for use in a class
exercise. It comes with several well-known sorting algorithms already built in,
so you may simply run it to illustrate them. But its true intended use is to
assign different algorithms to different individuals or teams in the class, to
let each come up with their own visualized implementation of the algorithm. When
all is done, they can all be assembled together into one grand improved
"class showcase" SortWatcher program, with a button for each
student-implemented algorithm in its button bar.
Download (Windows PC ZIP)
These files provided to the public without restriction.
Support for new visualized algorithms is provided
through three simple classes: VisInt stands in for int, or other type of the
elements to be sorted VisVector stands in for apvector<int>, or other type
of the array to be sorted VisIndex stands in for int, wherever int is used as an
index into the array. Each of these types can be used just like the type it
stands in for, except in the constructor, where some extra visual information
must be provided. The whole framework makes it quite easy to adapt a sorting
program based on apvector<int>, into a visual sorting module under
If you, the teacher, are assigning such an
exercise, you may wish to strip out most of the provided algorithms, before
making it available to students. To do so, just look in Algorithms.txt and
reverse the process (Step 5) of installing an algorithm.
An Introduction to Recursion
CheckerCheckerBoardBoard starts out looking like a 3x3 checkerboard. Click on
any square, and it changes state. But you will soon find that every square has
three states, not two: blue, yellow, and other. And what is other?? A recursive
image of the whole! But that is for the student to figure out, while playing
I envision this little program as a first
demonstration of recursion, in a visual form. But it may also be useful as a
programming exercise, to ask the student to replicate it. The program takes good
advantage of the Drawbox Rect class, which makes it very easy to subdivide a
rectangle into an array of equal sub-rectangles.
Download (single source
(Note: students will try to use large numbers of
squares, thinking to get a cooler image. Discourage this, because it doesn't
work. The best numbers are 5 and under, because they allow for deep recursion.)