%   MovieGrid.m

%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION. 


x=480;
y=640;
ImMat=zeros(x,y,3);
a=8;
b=a;
                                                                     
c=1;
NRow=12;
NCol=16;
figure
hPicAxes=axes('Units','Normal','Position',[0 0 1 1]);
Print2Path='Paul:Movies:SmallMirrorGrid:'
for RowInd=1:NRow
	for ColInd=1:NCol
		ImMat(:,ColInd*(y/NCol),:)=ones(x,1,3);
		ImMat(RowInd*(x/NRow),:,:)=ones(1,y,3);
	end
end
NTot=(NRow-1).*(NCol-1)-1;
RandVec=randperm(NTot+1);
RandVec=RandVec(find(RandVec~=((NRow-1)*(NCol-1)+1)/2));
test=find(RandVec==83)
iii=0;
RowInd=NRow/2;
ColInd=NCol/2;
ImMatFix=ImMat;
ImMatFix(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,1)=ones(2.*a+1,2.*b+1,1);
ImMatFix(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,2:3)=zeros(2.*a+1,2.*b+1,2);

ImMatFix(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-c:ColInd*(y/NCol)+c,1:2)=zeros(2.*a+1,2*c+1,2);
ImMatFix(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-c:ColInd*(y/NCol)+c,3)=ones(2.*a+1,2*c+1,1);

ImMatFix(RowInd*(x/NRow)-c:RowInd*(x/NRow)+c,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,1:2)=zeros(2*c+1,2.*b+1,2);
ImMatFix(RowInd*(x/NRow)-c:RowInd*(x/NRow)+c,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,3)=ones(2*c+1,2.*b+1,1);

RowCol=zeros(NTot,2);
for i=1:NTot
		%=============================
		for j=1:1
			iii=iii+1;
			if iii<10
				IndStr=['00' int2str(iii)];
			elseif iii>9 & iii <100
				IndStr=['0' int2str(iii)];
			elseif iii>99 & iii <1000
				IndStr=[int2str(iii)];
			end
			Print2FilePath=[Print2Path,IndStr];
			Print2FileString=['print -djpeg','100',' ',Print2FilePath];
			image(ImMatFix)
			axis('off');
			hold off
			pause(.1)
			eval(Print2FileString)
		end
		%=============================
		iii=iii+1;
		ii=RandVec(i)
		RowInd=ceil(ii./(NCol-1))
		ColInd=ii-((RowInd-1).*(NCol-1))
		RowCol(i,1)=RowInd;
		RowCol(i,2)=ColInd;
		ImMatTmp=ImMat;
		
		ImMatTmp(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,1)=ones(2.*a+1,2.*b+1,1);
		ImMatTmp(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,2:3)=zeros(2.*a+1,2.*b+1,2);
		
		ImMatTmp(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-c:ColInd*(y/NCol)+c,1:2)=zeros(2.*a+1,2*c+1,2);
		ImMatTmp(RowInd*(x/NRow)-a:RowInd*(x/NRow)+a,ColInd*(y/NCol)-c:ColInd*(y/NCol)+c,3)=ones(2.*a+1,2*c+1,1);

		ImMatTmp(RowInd*(x/NRow)-c:RowInd*(x/NRow)+c,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,1:2)=zeros(2*c+1,2.*b+1,2);
		ImMatTmp(RowInd*(x/NRow)-c:RowInd*(x/NRow)+c,ColInd*(y/NCol)-b:ColInd*(y/NCol)+b,3)=ones(2*c+1,2.*b+1,1);

		Ind=(ColInd-1).*NRow+RowInd
		if iii<10
			IndStr=['00' int2str(iii)];
		elseif iii>9 & iii <100
			IndStr=['0' int2str(iii)];
		elseif iii>99 & iii <1000
			IndStr=[int2str(iii)];
		end
		Print2FilePath=[Print2Path,IndStr];
		Print2FileString=['print -djpeg','100',' ',Print2FilePath];
		image(ImMatTmp)
		axis('off');
		hold off
		eval(Print2FileString)
		pause(.1)
end
SaveAscii(RowCol)
