I just completed a new art-toy: PlayWithMozart. To play, click on young Mozart’s image, below.


Be sure to come back here and leave a comment if you enjoy the program of if you have any questions or suggestions. I plan to make the code available in a few weeks, after I have a chance to comment it.

The idea

The idea was simply to try to adapt Mozart’s Musical Dice Game, so that the choice of measures is not random, but deterministic in some fashion. Thus came the idea of drawing a melody line and have the program choose the measure that best fits the melody line.Mozart wrote a minuet with 176 measures. He also created two matrices of 11 rows and 8 columns (look at it as one matrix with 16 columns). Each cell in the matrix contains a serial number referring to one of the 176 measures in the minuet. In the Musical Dice Game, the player rolls two die, thus producing a number between 2 and 12 — corresponding to one of the 11 rows of the matrix. For the first measure, one throws the die and selects the measure in the appropriate row of the first column. For the second measure, one throws the die again and selects the measure in the appropriate row of the second column, and so on. The resulting composition is a re-arrangement of the measures of the original minuet. The brilliance of Mozart was writing 16 sets of 11 measures, such that any of the 11 measures of a set can succeed any 11 measures of the previous set, while sounding good musically (actually Mozart cheated a little bit; the last set only has 3 unique measures, as some measures are repeated in the set). Several sites explain this game and its history; I found this site and this one very useful.Instead of “playing the dice”, the program PlayWithMozart selects the measure that best fits the outline of the melody you have drawn, taking into account whether the melody line is rising or falling, and the average pitch of the melody line for that measure. It does constrain the choices to the set of 11 measures available at any point. In addition, it also penalizes measures previously chosen, so as to force more variety, so that all 176 measures will eventually be used. So, how satisfactory are the melodies resulting from this collaboration with Mozart? Try it for yourself!

Coding tools

After playing with ActionScript a few years ago, I switched to Java and later Processing, because of their then faster execution speed, wonderful IDE (eclipse) and wide variety of open-source libraries. While I find that Java really works well on the desktop, I have grown a little impatient with the time it takes to load applets to the browser and the fact that the browser locks while the applet is being loaded. With ActionScript 3.0, the recent improvements in the Flash Player, and he ability to use Eclipse with Flex, I decided to try Flex. I found the experience of programming Flex/ActionScript quite enjoyable, and was pleasantly surprised by the speed and responsiveness of the result (PlayWithMozart). I do miss the more advanced syntax checkers, style checkers, code formatters, and refactoring tools available for Java – though I expect Flex to catch up.

Producing sound with Flash/ActionScript

I first tried to use Flash’s built-in sound library for PlayWithMozart and was quite disappointed with my inability to control timing precisely. I tried a variety of strategies, but I found it difficult to synchronize separate sound clips. It sounded like timing was off by a significant amount. To confirm this, I wrote a quick Flash program to produce a repetitive beat and recorded the output. Looking at the attacks on the waveforms produced, I found that the beats were off by up to +/- 16 ms. I was about to abandon my project when I stumbled upon Andre Michelle and Joa Ebert’s wonderful Popforge library. With it, I am able to play and apply sound effects to 8 simultaneous stereo tracks, at 20500 Hz, using about 10 to 25% of the CPU. If you want to dynamically sequence sounds, or even synthesize them on the fly, using Flash, I recommend you look at the Popforge library.On a related subject – the piano sounds. Originally, I had planned to embed the waveforms for all 88 piano keys. However the resulting sound file was large and the Flex application was taking too long to load in the browser. So I decided to only use one waveform per octave and have the program pitch-shift that waveform dynamically, as needed, for the other keys of the octave. Some richness of the sound was lost, because all keys in the same octave a clones of each other, but this approach reduced the loading speed by about 90%. On reflection, I think a better compromise would have been to use two keys (e.g. C and G) per octave.

hairSynth – a hair drawing program

With hairSynth, you can easily create drawings of hair. This can be done directly in your browser, or you can download hairSynth to your computer (works on any computer that runs Java) and save the completed drawings in PostScript format for further manipulation in Illustrator or conversion to JPEG via Photoshop. To play with hairSynth, click on the image below


For detailed instructions and to download the program and source code, click here.


cutNwatch – an interactive toy that runs in your browser. Draw a line, watch it as it cuts a surface, then watch the surface deform and recover.

Click here to play.

For more details, including source code, click here.




RippleTiles – an interactive cellular automaton. Click on the image below to play.



DiskDrummer – a simple interactive drum box. Click on the image below to play.



Boxers – Two to 5 boxers confront each other. Fight or flight. No punches yet. Click on the image below to watch.


Wild Pizza Dough

Wild Pizza Dough – my entry to BIT-101 2002 “25 lines of coe max” contest. Click on the image below to watch.



LocoMomo, is an interactive art-toy which blends a little engineering with a surrealistic image (find the image). Turn on the sound! Click on the image below to play.



Messages – a rendering of a synthetic email flow. Non-interactive. Click on the picture below to see.



Expandor – expanding concentric frames. Non-interactive. Click on the image below to watch (should not be viewed by persons with photosensitive epilepsy).