Often seen in science museums, the harmonograph is a device that combines wave motions (e.g. from some pendulums) to move a pen resting on a sheet of paper. These movements result in attractive patterns. This device can be simulated easily in a computer program such as the following one. The principle is that the wavy motions are represented by sine waves (one per pendulum). They are effectively Lissajous figures decaying over time.

The attraction of the harmonograph is largely due to the closely spaced, almost parallel wavy lines. There’s 2 contributors to that: the motion decay (due to friction in the real device), and the fuzzy integers make the periodic orbits slightly miss their previous trajectory. Think of the Lissajous figure: when the x y frequencies are integral the trace stays still; change one and the figure starts to rotate.

The following program is an extensible harmonograph simulator – you can easily change the number of pendulums or the number of dimensions to plot in. Usually harmonographs are drawn using 2 or 3 pendulums in 2 dimensions, but you can add more! Each run plots a random harmonograph, choosing a near-integer number (a fuzzy integer, e.g. 3.004, 6.998) for each frequency. This tends to generate good pictures. Numbers that aren’t near-integer tend to make messy pictures.

The motion of a damped pendulum is x = A * sin (t * f + p) * e^{-d * t}, where A is the initial amplitude, t is time, f is the frequency, d is a damping factor due to friction, and p is the initial phase (where in the sine wave the pendulum starts). In many implementations the damping factor is given by an exponential decay function, but we’re happy to simply multiply by a number that we scale down slightly per time step. And finally there is a constant scaling factor to fit the motion into the drawing area.

We simplify things by setting all amplitudes to 1, with little loss, if any, of aesthetics. Allowing amplitudes to be small diminishes all the efforts the sine waves go to to bring you pretty patterns!

### Program Notes

- You need these libraries: turtle, random, colorsys, math. They are already installed with Python.
- Some features e.g. colorsys aren’t available in Trinket so they’re commented out and say ‘nit’.
- If you want more than 2D you’ll need an appropriate plotting library, e.g. vpython for 3D (but not yet in Python3.
- You can select to plot in black on white or colour on black, or edit to choose your own colours.
- Parameters: window size, # of pendulums, etc. Play with these to your heart’s content!
- fuzzint(mf,sd) returns a random near-integer in the range 1 – mf. sd is the ‘fuzziness’.
- Frequencies and phases are computed inside a little Python list of lists magic.
- Set up turtle graphics. Click on canvas to exit.
- while dec > end: dec is the decay factor, the loop terminates when the motions have decayed…
- Compute xy coordinates inside another bit of Python magic. Note that p & q are ‘reversed’: [q][p]
- Run & enjoy!

### Further Information

- Harmonograph by Paul Bourke
- Harmonographs by me at FractalArt.Gallery

[welcomewikilite wikiurl=”http://en.wikipedia.org/wiki/Harmonograph” sections=”Short description” settings=””]