Windows Holes
Volume Number: 3
Issue Number: 10
Column Tag: Pascal Procedures
Blasting Holes in Windows
By Greg Marriott, MacHax™ Group, Bryan, Texas
How To Build A Laser Cannon: A Home S.D.I. Project
Bit O’ History
I wish I came up with the idea to blast holes in windows, but I didn’t. The credit
goes to Andrew Donoho and Darin Adler. Andrew is the author of MacSpin, a 3-d data
analysis tool. MacSpin allows a user to rotate a “cloud” of data points around any of
three axes in real time. Because of its highly interactive nature, Andrew likes to refer
to it as a thinking man’s video game. He and Darin got together and decided that
MacSpin was missing a feature essential to successful video games: laser cannons.
They envisioned a user holding down command-shift-option-capsLock and being
rewarded by laser turrents appearing in the corners of the data window. Add in some
crosshairs with range and elevation readouts, and the user could blast away! They
figured laser cannons would be e specially useful in MacSpin, where unwanted data
points could be annihilated, thus saving a pet theory from bothersome reality.
Andrew continued to joke about actually implementing laser cannons. That’s how
my partner, Scott Boyd, heard about it. Scott was working closely with Andrew on
enhancements for MacSpin when the subject of laser cannons came up. Scott knows a
good idea when he hears one (most of the time), so he immediately urged Andrew to
stop joking and do it. More pressing concerns kept them both busy for a while, but the
idea wouldn’t die.
Laser Cannons Are Born
I learned about laser cannons in a phone conversation with Scott. I know a good
idea when I hear one, too (I hope...). They were busy. I wasn’t. By the time Scott
came home from Austin a couple of days later, I had the first incarnation of Blast
finished. It was an application that brought up a window, and made holes wherever the
cursor was when the mouse button was pressed. The holes were plain and round, and it
ran silently. The holes weren’t even centered under the cursor. But gridlines drawn
in the window showed that the holes were “not there.” That is, holes had been cut out
of the structure of the window. Wow laser cannons.
Fig. 1 Blasting holes in Full Paint's windows! (note how the cursor changes over a hole
to the arrow, proof that it is not in the window!)
“Useless Interface” Concerns
Scott and I talked about what the holes should look like. After some discussion, he
drew some sample holes in MacDraw. After a while, he had something we both liked. I
took the coordinates of the vertices around the hole, and put in some code to make a
region (instead of just using circles). While I was at it, I started centering the hole
under the cursor. So far, so good.
Sound came next. Poking holes in things isn’t very much fun if you don’t get
some sort of aural feedback. We discussed all sorts of options, from simple beeps to
elaborate crashing noises. I chose the easy route and used the Sound Driver to make
some square-wave sound.
Making sound on the Mac is pretty easy if you’re willing to settle for single voice
tones. Each tone is described by a trio of values known as a “triplet.” These numbers
describe the pitch, volume, and duration of the tones you want to play. I decided to use
twenty triplets. The last triplet has zero for all three values, to tell the Sound Driver
to stop making noise. For the other nineteen, I chose a starting value, then decreased
the pitch and volume of each succeeding tone. This gives the impression of something
moving into the distance, like a train’s whistle as it heads away from you.
Now We’re Getting Somewhere
Blast didn’t change much after I added sound. The biggest change was in
“packaging.” I wanted Blast to be available from anywhere, so I decided to make it into
an FKEY. But as an FKEY, Blast had to stop counting on having access to global
variables and resources. QuickDraw globals such as screenBits and thePort may not be
available while an FKEY is running. And, counting on certain resources being installed
along with the FKEY is a sure way to see everybody’s favorite bomb box. So, Blast
became a procedure in a UNIT. The procedure has everything in it Blast needs to do its
dirty work. [The version presented here is compatible with both MPW Pascal and LS
Pascal. The unit can be either installed as an FKEY or you can call the unit from a