App Icon  Lines & Bubbles 20th Anniversary Edition

I wrote Lines, and then Bubbles, back in 1985, for the then-new Apple Macintosh computer, and it caused some excitement then, in those simpler days. Now, 20 years later, here are Lines and Bubbles, together in one application.


Download Lines & Bubbles for Microsoft Windows.

The source code for Lines & Bubbles.

Download Lines & Bubbles for MacOS, both the application and the source code, lightly updated to compile and run on MacOS 8.6 with Metrowerks Codewarrior Pro 4 and some version of Apple's Universal Headers. Download my Shell for MacOS if you want to build Lines & Bubbles.


Lines is simply my own version of a now-common screen saver drawing random moving line patterns or other shapes, nothing you haven't seen before.

Bubbles draws randomly placed circles that can be dragged, resized, or popped, and which can bud off new bubbles like yeast.


When run with no command line parameters, say by double-clicking on Lines.exe, a Lines window and a Bubbles window with 5 bubbles are made, just so the program clearly does something. When you make a new window, it splits off from the top window (if any); if it is the same kind of window, it will inherit the top window's settings.

A Lines window can either "undraw" (erase) the pattern as it is drawn, or leave the entire pattern on the window. It can repeat the same pattern continuously, or move to a new pattern after a few seconds. If repeating, it can step to another pattern on command. It can draw various figures that can be specified by two points: Lines, Boxes, or Ovals; it can trace Lissajous figures for each point to the next; or it can draw a plot I found useful when debugging the original program on the Macintosh.

A Bubbles window can have up to 200 bubbles in it. They can have a downward push I call Gravity applied to them, to make them more active; they can be colored ("Designer Bubbles") or clear; and they can bud off new bubbles like Yeast, which will grow to the size of the parent bubble. Bubbles bounce around madlyf there are more bubbles than fit. Click and drag a bubble to move it. Shift-click (or use the menu) to get a Pin cursor that pops bubbles. Control-click (or use the menu) to get a Wand cursor and drag to blow a bubble to a different size; subsequent bubbles made will be that size.

If you want to get fancy, you can use the command line, say in a Shortcut, to control which windows are made and their settings. Command line parameters can be abbreviated, and capitalization doesn't matter. They are almost a little language:

-lines  Make a new Lines window.
-bubbles  Make a new Bubbles window.
-next  Activate the next window (does nothing if no window).

Windows inherit from the window they're split from, if the new window is the same kind as the old window; otherwise they get default settings. The -next command allows making a new window and then working on the old window.

If the top window is a Lines window, the default settings are Erasing, not Repeating, Lines; and the commands are:

/erase  Turn Erase Behind off (or on again).
/repeat  Turn Repeat on (or off again).
/step  Step to the next pattern.
/lines  Draws Lines.
/boxes  Draws Boxes.
/ovals  Draws Ovals.
/lissajous  Draws Lissajous figures.
/plot  Draws a debugging Plot.

If the top window is a Bubbles window, the default settings are no Bubbles, no Gravity, Designer bubbles, Yeasting on; and the commands are:

/make  Make a Bubble.
/gravity  Turn Gravity on (or off again).
/design  Turn bubble colors off (or on again).
/yeast  Turn Yeasting off (or on again).

For example, if you make a shortcut to Lines.exe, open the shortcut's properties, and add the following to the end of the Target field:

-lines -bubbles /make /make /make /make /make

the Shortcut will mimic the default settings. If you instead set the end of the Target field to:

-lines -bub /make /make -bub -next -next /ovals

the Shortcut will make a Lines window on the left and two Bubbles windows on the right. The upper Bubbles window will have two bubbles, and the lower one will have none. The Lines window will be on top, and will draw ovals.


I wanted to write software that worked the way a Macintosh should. As I re-tool as a Microsoft Windows programmer, it seems appropriate to update Lines and Bubbles.

Apple's example applications in the early years of Macintosh were just dreadful, and Apple warned against using them as examples of how to write Macintosh software. Each one had a large event loop, with a switch on the event code. In each case in the switch, there was another switch for each window in the application. Adding a new window involved adding a new case to every such switch, all over the application, and got harder as the application grew.

Lines, and then Bubbles, were simple applications I wrote in 1985 to show how to properly structure a program's event loop so that each window was independent, and to demonstrate my skills as a Macintosh programmer. Lines in particular created, well, astonishment in the local Boston-area Macintosh community, notably in the Macintosh group of The Boston Computer Society, as it showed both simple animation and multi-tasking. Lines was a very simple application that handled only a few types of events. It didn't even need to properly handle update events, as it is continually drawing and (usually) erasing, and then switching to a new pattern.

I had noticed that the handling of events for any window broke into two main cases: basic stuff that was the same for every window of any kind, and the details that made each particular window be what it was. I made an event loop that did the basic stuff, and dispatched the decoded and digested events to the destination window via a function pointer stored with the window. I didn't know it, but I was re-inventing Windows, much the way that Microsoft did it with WNDPROCs. Over time, this developed into my Shell, which I used to write most of my Macintosh software. Bubbles was one of my first Shell'd programs, and was more sophisticated than Lines, handling more event types.

Though I got several programmers in the BCS MacTechGrp to look at my Shell, I was never able to make my Shell popular with other programmers. Eventually, Apple developed MacApp, which at least made the basic structure of applications moot.

A fair amount of thought went into how Lines would make its lines, including much optimization to make the program fast on the Macintosh of the day. Floating point was slow, and transcendental functions, such as Sine or Cosine, were right out. In the port to Windows, I've had to remove most of that optimization, as floating point is now fast, and many of the tricks I used were too hard to port, especially those written in 68K assembler. It's just part of the march of progress.

The Windows versions of Lines and Bubbles also sport color graphics, which were years in the Macintosh's future when I originally wrote the programs. In Lines, color replaces line styles in the Plot variant, and enhances the appearance of the various patterns. In Bubbles, color replaces the varied patterns provided by the Macintosh when drawing designer bubbles.

Lines draws moving patterns of shapes that can be defined by 2 points. Lines randomly creates its patterns by generating random quantities for the rate, length of the pattern, and amplitude, and then 8 random points, 2 for each endpoint of the lines, and 3 for the colors (1 is wasted), and 8 random phases and rates. The points are transformed into center and magnitude, and are used to scale sine table entries that are read out at the random rate starting at the random phase. In effect, the line or other shape endpoints trace out Lissajous patterns bounded by the original endpoints. The color entries are used as 3D points in HSV space, so that the saturation and brightness can be limited, and are transformed into RGB as the pattern is read out. The resulting pattern is stored in an array so that it can be repeated and erased.

Bubbles creates its bubbles at random locations in the window, with random colors (formerly randomly chosen entries from the System Pattern List). The heart of Bubbles is the Avoidance algorithm. It is fairly unsophisticated, in that each bubble acts on the bubbles it is found to be touching, in sequence, rather than bubbles acting on each other symmetrically and simultaneously. For each bubble that needs checking, its distance to each other bubble is checked, and, for bubbles close enough to touch, the other bubble is moved away so it no longer overlaps the bubble being checked, and is then put on the list of bubbles that need checking. Then the bubble being checked has "gravity" applied, and is tested against touching the walls and moved back onto the window if needed. In the Macintosh versions of Bubbles, all the math was done in integers, so bubbles had a tendency to stick a bit and they often got into repeating loops, when the amount being moved either horizontally or vertically was less than 1 pixel. In the Windows version, bubble positions are floating point values, so bubbles can move by much smaller amounts and therefor don't stick to each other or loop so much.

On Windows, Lines & Bubbles is a Multiple Document Interface (MDI) application, as that is the way that multiple-window applications are done on Windows. On old MacOS, an application's windows were kept in a "layer", much like a single irregularly-shaped window from the perspective of other applications. On MOSX, Apple recommends that applications have only one window.


Back to Tony NelsonJHC's R Pentomino's Home Page

Valid HTML 4.0!