A texture that changes while the game runs. The ground is one picture painted in code; a click cuts a crater out of it with a transparent fillCircle, and updatePixelTexture sends only the rectangle around the crater to the graphics card, not the whole picture. That is what keeps a big picture that changes a little every frame cheap: a minimap filling in, fog of war lifting, a floor you can dig.
The same picture is also the collision. Each ball asks getPixel whether the pixel under it is solid, so the balls over a new crater fall into it. There is no second copy of the ground to keep in step with what is drawn.
Click to dig.