The code is the easy bit the hard bit is getting a machine that can follow the code instructions, you need the X or Y axis to be in sync with the spindle. Then the code is generated using Sin and Cos of a selected arc length on a offset centre point, the Z movement is then divided into the number of cords.
If you make the conforming machine I will write you the code.
Graham