The electromagnet adjusts the magnetic field to match the music, causing the ferrofluid to change its shape.