% % Draws a grid filled with hollow or filled non-overlapping squares % positioned at random % Not programmed with efficiency in mind, thus it gets fairly slow for % larger Ns. % % Anders Hoff February 2010 clear; clc; close all; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% N = 700; %size of grid minSize=2; %minimum square size. 1 is not recommended %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% M=N+2; %size of matrix rep=1000000; %break off number of repetitions breakOff = 200; %number of unsuccessfull loops before termination mSize=ceil(N/5); %max size of square %create MxM matrix boreder by 3s A = zeros(M); one=ones(1,M); A(:,1)=one; A(:,M)=one; A(1,:)=one'; A(M,:)=one'; sizes=0; count=0; for a=1:1:rep count = count +1; tup = findTuple(A,N); x=tup(1,1);y=tup(1,2); size=randSqr(x,y,A,mSize); if size >= minSize A = drawSqr(x,y,size,A); sizes=[sizes size]; count = 0; end if count >= breakOff break; end end %remove internal points %i have a feeling there is a more efficient way of doing this for c = 1:1:M for d=1:1:M if A(c,d) == 1; A(c,d)=0; end end end figure(1); imshow(A,[0 3]);