front = [28, 38, 48];  % Number of teeth on front sprockets
back = [32, 26, 21, 18, 16, 14, 12, 11]; % Teeth on back sprockets

[frontrep, backrep] = meshgrid(front, back);

ratio = frontrep ./ backrep;
flat = reshape(ratio, [1, numel(ratio)]);
[sorted, idx] = sort(flat);

frontnum = ceil(idx/8);
backnum = mod(idx, 8);
backnum(backnum == 0) = 8;

result = [frontnum', backnum', sorted'];

outfile = fopen('out.txt', 'w');

fills = {'ff0000', '00ff00', '0000ff'};

for ii = 1:length(sorted)
    % Rectangle
    fprintf(outfile, ...
    [ '<rect \n', ...
      'style="fill:#%s;fill-opacity:1;stroke:none"\n', ...
      'width="200"\n', ...
      'height="2"\n', ...
      'x="0"\n', ...
      'y="%.2f" />\n\n'], fills{frontnum(ii)}, sorted(ii)*100);  
end

% Text labels
for ii = 1:length(sorted)
    % Text label
    fprintf(outfile, ...
      ['<text\n', ...
       'xml:space="preserve"\n', ...
       'style="font-size:12px;font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:TeX Gyre Pagella;-inkscape-font-specification:Sans Italic"\n', ...
       'x="250"\n', ...
       'y="%.2f"\n', ...
       'sodipodi:linespacing="125%%"><tspan\n', ...
       '  sodipodi:role="line"\n', ...
       '  id="tspan3216"\n', ...
       '  x="60"\n', ...
       '  y="%.2f"\n', ...
       '  style="font-style:normal;-inkscape-font-specification:Sans;font-family:Sans;font-weight:normal;font-stretch:normal;font-variant:normal">\n', ...
       '1:%.2f\n', ...
       '</tspan></text>\n'], sorted(ii)*100, sorted(ii)*100, sorted(ii));
end
     
