Rolling Rod of Bevel Gears

Input: orange bar.
All the gears have the same tooth number.
The gears are fixed to the bar of their colour.
Grey gear is fixed to the grey base.
Angles between adjacent bars are kept equal to the input angle A during the motion.
If A = 90 deg., the four bars create a square.
If the bar number is n, the bars can create an equilateral polygon of n sides when A = 360/n.