%Chapter 5, Example 5.3: Fig 5.3 (a)
%Eric Dubois, updated 2018-11-16
%Create test pattern of example 5.3 as an image 
%Required functions: Lattice_Points_2d, ds2nfu by Michelle Hirsch
clear all
close all
%Sampling matrix and extent for periodicity lattice
VG = [4 2;0  1.5];
UL = [-5 -6]';
LR = [5 5]';
%get the points of the lattice in the desired region 
xoutG = Lattice_Points_2d(VG,UL,LR);

%create the plot
figure

%Plot the background in black
rectangle('Position',[-5 -5 10 10],'FaceColor','black');
axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-5, 5]);
ylim([-5, 5]);
hold on

%Plot the diamonds on the points of Gamma
diam = polyshape([1 0 -1 0],[0 1 0 -1]);
nptGamma = size(xoutG,1);
for rpt = 1:nptGamma
   diamT = translate(diam,xoutG(rpt,:));
   plot(diamT,'Facecolor','white','FaceAlpha',1,'EdgeColor','white');
end

%Plot the squares on the points of Gamma
square = polyshape([.25 -.25 -.25 .25],[.25 .25 -.25 -.25]);
for rpt = 1:nptGamma
   squareT = translate(square,xoutG(rpt,:));
   plot(squareT,'Facecolor',[.5 .5 .5],'FaceAlpha',1,'EdgeColor',[.5 .5 .5]);
   squareT2 = translate(square,xoutG(rpt,:)+[0 1.5]);
   plot(squareT2,'Facecolor',[.5 .5 .5],'FaceAlpha',1,'EdgeColor',[.5 .5 .5]);
end

set(gcf,'Color',[1 1 1]);
