a = 1;
Nx = 150;
Ny = 150/2;
Nyy = Ny*2;

A = zeros(Nx,Nyy);
centers = A; %when calling set_hex(i,j,A), must also set centers(i,j) = 1

i = 15; j = 15;
A = set_hex(Nx/2,Nyy/2,A);
centers(Nx/2,Nyy/2) = 1;
newA = A;
oldCenters = centers;
numIter = 31;

for i = 1:numIter
    for x = 5:Nx-5
        for y = 5:Nyy-5
            if (oldCenters(x,y) == 1)
                [nextdoor_x,nextdoor_y] = getNeighbors(x,y);
                for n = 1:6
                    nx = nextdoor_x(n);
                    ny = nextdoor_y(n);
                    if (oldCenters(nx,ny) == 0)
                        count = 0;
                        [next_x,next_y] = getNeighbors(nx,ny);
                        for c = 1:6
                            if (oldCenters(next_x(c),next_y(c)) == 1)
                                count = count + 1;
                            end
                        end
                        if (count == 1)
                            newA = set_hex(nx,ny,newA);
                            centers(nx,ny) = 1;
                        end
                    end
                end
            end
        end
    end
    plot_hexagonal_lattice(newA);
    whitebg(1,'k');
    set(gcf,'color','black');
    set(gcf, 'InvertHardCopy', 'off');
    axis off
    set(gca,'XTickLabel',[]);
    set(gca,'YTickLabel',[]);
    drawnow;
%     saveas(gcf,['basicSnowflake_',sprintf('%05d',i),'.png']);
    oldCenters = centers;
end
