Two bodies are in a mean-motion resonance when their orbital periods form a simple ratio. Three views of the same idea: where the repeated conjunctions happen, what those repeated kicks do to an orbit, and what they do to a whole population.
A planet on a circular orbit and a smaller body on a Keplerian orbit with a chosen period ratio. Every time they line up on the same side of the star, a marker is dropped where the body was. Whether the markers pile up or smear around the orbit is the whole difference between a resonance and no resonance.
What to try. With a simple ratio the markers land on the same few spots forever; nudge the slider off the ratio and they creep around the orbit. For the Pluto preset the two orbits cross, yet with conjunctions at the body's apocenter the closest approach stays large. Drag the conjunction slider toward 0° and watch the closest approach collapse: same orbits, same ratio, wrong phase. The rotating frame shows the body's path as the planet sees it, which is how the Pluto and Trojan pictures are usually drawn.
This screen is pure Kepler: the planet has no mass here. The other two screens turn gravity on.
Now the planet has mass. A small body starts on a nearly circular orbit at exactly the resonant semi-major axis. Watch what the repeated conjunctions do: the semi-major axis stays locked while the eccentricity grows. The magenta outline is the ellipse the body is on right now; the plots track its eccentricity and the resonant angle φ = qλ − pλp + (p−q)ϖ.
What to try. Let the 2:1 case run until the ellipse is obvious, then restart at 3:1 with the same near-circular start at one Jupiter mass: almost nothing happens for a very long time. Add some starting eccentricity and it takes off. First-order resonances (2:1, 3:2, 4:3) pump a circular orbit directly; second-order ones (3:1, 5:2) need a seed, because their forcing scales as e2 rather than e.
About the mass slider. At one Jupiter mass the pumping is slow, so the counter shows how many planet orbits have elapsed. Raising the mass makes the libration faster and the eccentricity swing larger; it exaggerates the effect rather than changing its character. Push it far enough and close encounters take over and the body can be scattered or ejected.
Units: the planet orbits at radius 1 around a star of mass 1, with G = 1. Elements are heliocentric and osculating.
A few hundred test bodies spread across semi-major axis inside a massive planet's orbit, each on a nearly circular orbit. Bodies near a resonance have their eccentricities pumped until they cross the planet's orbit (or an inner planet's) and are removed. The histogram beneath shows the gaps carving themselves out where the resonances sit, as in the asteroid belt's Kirkwood gaps.
Honesty about time. Real Kirkwood gaps take millions of years to open, which at one Jupiter mass would mean an hour or more of watching. The default here uses ten Jupiter masses, which opens the gaps in minutes and exaggerates their width. Set the mass to 1 to see how slowly the real thing happens; the elapsed counter tells you how long it has been in Jupiter-years.
Each gray bar in the histogram is the starting population; the blue bars are what is left. The dashed lines mark where each resonance sits. Bodies are removed when their orbit crosses the planet's or the inner planet's, or when they are scattered out of the system.