R=1;
r=0.91;
p=0.075;
t=[0:0.1:100*6.28];
scale=20;   % scaling factor: mm

k=r/R;
l=p/r;
x=((1-k)*cos(t)+l*k*cos(((1-k)/k)*t));
y=((1-k)*sin(t)-l*k*sin(((1-k)/k)*t));

s = 0.5*scale/max(x);
x = s*x;
y = s*y;

x0 = x(1);
y0 = y(1);
dx = diff(x);
dy = diff(y);
nx = [x0 dx];
ny = [y0 dy];

plot(x,y);

f=fopen('spiro.py', 'w');
fprintf(f, "def layer_pattern():\n");
fprintf(f, "    p = [\n");
for i=1:length(x)
    fprintf(f, "    [%f,%f,0,0,0,0],\n",nx(i),ny(i));
end
fprintf(f, "    ]\n");
fprintf(f, "    return(p);\n");
fclose(f);
