If the number of teeth on the cog does not evenly divide the number of teeth on the wheel then we may have to go round several times before the pattern joins up again. For example, if the wheel has 144 teeth and the cog has 64 then we have to go round twice.
The code is Pattern3.java.
We can get an interesting swirl by repeating the pattern above several times and, each time, choosing a different hole for the pen and a different tooth on the rim of the wheel to start.
The code is Pattern4.java.
Simple Patterns
SpiroGraphics
Flower Patterns