image thumbnail

Kolam Generator

by

 

30 Apr 2012 (Updated )

This suite of functions can be used to generate geometric line drawing of Kolams.

[N,len,Island]=count_islands(M)
function [N,len,Island]=count_islands(M)

pt_dn=[0 1 0 0 0 1 0 0 1 0 1 1 1 0 1 1];
pt_rt=[0 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1];

mate_pt_dn{1}=[2 3 5 6 9 10 12];
mate_pt_dn{2}=setdiff(2:16,mate_pt_dn{1});
mate_pt_rt{1}=[2 3 4 6 7 11 13];
mate_pt_rt{2}=setdiff(2:16,mate_pt_rt{1});

PMat=ones(size(M)+1);
PMat(2:end,2:end)=M;
Island=zeros(size(M)+1);
Max_no=1;
for i=2:size(PMat,1)
    for j=2:size(PMat,2)
        connects_down=pt_dn(PMat(i-1,j))==1;
        connects_rt=pt_rt(PMat(i,j-1))==1;
        
        cs= connects_down + connects_rt;
        
        switch cs
            case 0
                Island(i,j)=Max_no;
                Max_no=Max_no+1;
            case 1
                if connects_down
                    Island(i,j)=Island(i-1,j);
                else
                    Island(i,j)=Island(i,j-1);
                end
            case 2
                Island(i,j)=Island(i-1,j);
                I=find(Island==Island(i,j-1));
                Island(I)=Island(i,j);
        end
    end
end
Island=Island(2:end,2:end);
Lv=unique(Island);
N=length(Lv);
for i=1:N
len(i,1)=length(find(Island(:)==Lv(i)));
len(i,2)=Lv(i);
end
        

Contact us