Matlab Code to Draw Fibonacci Checkerboards

Here is the Matlab code that generates the Fibonacci checkerboards. The variable n specifies what modulo is used, and hence the size of the board (it will be nxn). The a and b parameters choose which recursion is used to generate the sequence. As you change n, you will want to choose different color maps so that the board looks good. Standard rules for slide checkers are here.

% draw fibonacci checkerboards
% by Bill Sethares

clear
n=12;
a = 1; b = 1; % standard fibonacci checkerboard
checks = zeros(n+1);
thiscolor = 0;
for i=1:n
   
for j=1:n
      if checks(i,j)==0
      thiscolor = thiscolor+1;
      irun = i;
      jrun = j;
      checks(irun,jrun)=thiscolor;
      k=1;
      while k<n^2
         itemp = irun;
         irun = jrun;
         jrun = mod(a*itemp+b*jrun,n);
         if jrun==0, jrun=n; end
            checks(irun,jrun)=thiscolor;
            k=k+1;
         end
      end
   end
end
for i=1:n+1
   for j=1:n+1
      if checks(i,j)==0;
         checks(i,j)=thiscolor;
      end
   end
end
q=find(checks==0);
checks(q)==thiscolor;
figure(1)
pcolor(checks)
axis square
axis off
map = [ 1 0 0
        0 0 1
        1 1 0
        0 1 0
        1 1 1
        1 1 1
        1 1 1
        1 1 1
        1 1 1
        1 1 1];
colormap(map)
shading faceted

To get to my homepage, click here.