Saturday, March 20, 2010

A harmonograph in JavaScript

What's a harmonograph, you ask? Well, it's something like a Spirograph for grown-ups. A harmonograph uses a construction with pendulums to draw pretty patterns.

One particular incarnation uses two pendulums of nearly equal length, each about two metres. To the right pendulum, a slowly revolving disk is attached, which is driven by a small electrical motor. The drawing paper is taped onto the disk. To the left pendulum, an arm is attached with the pen at the end. When the pressure and thus the friction of the pen is sufficiently low, the pendulums can keep swinging for tens of minutes.

For learning and fun, I replicated this harmonograph in JavaScript with the HTML5 canvas element. The pendulum motion is approximated by a sine function, and friction by an exponential, but apart from that it should be pretty physically accurate.

Without further ado, I present to you: Harmonograph in JavaScript. Usage should be self-evident. Although some input validation is done, you will be able to break it with strange values.

With the link at the top, you can save and bookmark your creations or send them to your friends. Enjoy!

Update, 2017-01-22: Hosting is now done here on GitHub Pages. The old location redirects you. I also published the source code (“View Source” still works just fine, but it's now officially MIT licensed as well).


Ryan said...

This is an excellent piece of software, thanks very much for posting it.

Greg said...

I found another very cool harmonograph, capable of very cool patterns.

It is also written with HTML 5 Canvas and javascript.

Grahame Thompson said...

Hi, I'm trying to get in touch with you about using the harmonograph on our Science education website.

Please email me!

Kind regards,
Grahame Thompson

Thomas ten Cate said...

I would love to, but unfortunately you didn't leave your email address! In case you don't check back here, I've contacted the website that your username links to ( In case you do check back, drop me a note at ttencate at gmail dot com.

Micha said...

Hi Thomas,
our students will construct a harmonograph like your simulated model. The length of both pendulums should be among 1700 mm. In january we will start the building. I ´m a teacher (ma/phy). Could you please contact us? May be, there are any questions by the students...

Thomas ten Cate said...

I would, but you didn't leave your email address. Please get in touch via ttencate at gmail dot com!

electronic signature said...

A special thanks for this informative post. I definitely learned a few new things here.

Alex said...

Hi Thomas! This is so beautiful. I wanted to ask you some questions, do you still use the same email for me to contact you :)