In detail: Mathmos (Part I)

mathmos-small-1

Last summer, Mathmos asked us if we fancied doing something for the 45th birthday of their iconic Astro Lamp. We felt that a natural fit for this would be a screen saver that simulated the lava lamp.

From a coder’s perspective, this project had two interesting problems to solve. Firstly, we had to consider the physics at work inside a lava lamp in order to create a realistic simulation. Secondly, once you’ve figured out where your blobs are, their sizes and how they’re moving, you need to draw them in a satisfyingly blobby way.

In this first post, I’m going to talk about the physical model we created to simulate the motion of blobs in a lava lamp. You can read Part II here.

The Interesting Bit I: Lava lamp physics

When I was in secondary school, I ran across some instructions on the internet (at that point, it might even been on Gopher) on how to build a lava lamp. The recipe called for blobs of vegetable oil suspended in methylated spirits. I built it with my science teacher; it failed. But I’d learned a lot about how they work along the way.

In the base of the lamp, there’s a light bulb which illuminates the lamp and heats the liquid. This causes the blobs to rise to the top where they cool and sink back down again – a textbook example of heat convection. While they’re doing this rising and falling, they’re colliding with one another and glomming together to form new blobs, or breaking smaller blobs off as some regions of a large blob change temperature more rapidly than others.

To simulate this process, I started with a simple setup in APE: gravity, a few circle particles and box to hold them in. I then wrapped the basic particle class to give me particles that could have a certain amount of heat, which the system uses to apply an upwards force to each particle. The strength of that upwards force is dictated by a particle’s heat, which is increased while the particle is near the bottom of the system, but gradually cools over time to the point where gravity becomes stronger than the upwards force and the particle starts to sink.

That gave me masses which would rise and fall inside my simulated lamp, and half of my physical simulation.

The second step was to simulate the glomming together / breaking apart behaviour of the blobs. This is achieved by spawning springs between particles when they get within a certain distance of each other to make them drift together. These springs are quite loose, so as to create gentle motion, and also have a breaking point. The breaking point is important, as it allows particles to unstick from one another as gravity and heat force them in opposite directions.

This worked pretty well, and, once the spawning and breaking points and spring stiffness had been juggled sufficiently, we ended up with a system where nice blobby shapes formed from groups of particles coming together as they drifted past each other on their way up and down.

For extra bonus points, I added a stage where connected particles exchange mass downhill along their springs; this simulates an effect I noticed in lava lamps where blobs appear to flow into one another, and fuels the breaking off effect as the lower blobs become heavier and slow down relative to their rapidly shrinking conjoined siblings. This little touch made the simulation feel that much more realistic, and I’m particularly chuffed with the way it turned out.

Continue reading in Part II.

Tags: , , , , ,

Leave a Reply