%Chapter 4, Fig 4.1
%Eric Dubois, updated 2018-11-15
%Plot a periodic wallpaper pattern showing the periodicity lattice
%Based on abstract blue geometric wallpaper from murals wallpaper, UK
%https://www.muralswallpaper.co.uk/shop-murals/abstract-blue-geometric-wallpaper/
%Required functions: Lattice_Points_2d, ds2nfu by Michelle Hirsch
clear all; close all;
%sampling matrices and portion of R^2 to plot
K = 10;
VL = [.5/K 0; 0 .5/K];
VG = [1.5 1; -0.5 3];
UL = [-1 -1]';
LR = [9 7]';

%get the points of the lattices in the desired region 
xoutL = Lattice_Points_2d(VL,UL,LR);
xoutG = Lattice_Points_2d(VG,UL,LR);

%create the plot

figure

%plot the points
points = plot(xoutG(:,1),xoutG(:,2),'k.');
points(1).MarkerSize= 1;
axis equal
axis off
set(gca,'ydir','reverse'); 
set(gca,'fontname','times')          %set the plot font to Times
%set the region
xlim([0, 7.9]);
ylim([0, 5.9]);
hold on

%Draw the wallpaper pattern
% the pattern is made of four colored polygons replicated on the points of
% Gamma
nptGamma = size(xoutG,1);
% P4 = polyshape([0 -1 -1 -.5 -.5],[0 0 -1 -1.5 -.5]);
for rpt = 1:nptGamma
    patch([0 1 1 .5 .5]+xoutG(rpt,1), [0 0 1 1.5 .5]+xoutG(rpt,2),[.6 .675 .7],'EdgeColor','none');
    patch([0 0 .5 -.5 -.5]+xoutG(rpt,1),[0 1 1.5 1.5 .5]+xoutG(rpt,2),[.07 .24 .33],'EdgeColor','none');
    patch([0 .5 .5 -.5 0]+xoutG(rpt,1),[0 -.5 -1.5 -1.5 -1]+xoutG(rpt,2),[.07 .24 .33],'EdgeColor','none');
    patch([0 -1 -1 -.5 -.5]+xoutG(rpt,1),[0 0 -1 -1.5 -.5]+xoutG(rpt,2),[.6 .675 .7],'EdgeColor','none');
end

%label values on the axes
text(1.95,-.2,'2','FontName','times');
text(3.95,-.2,'4','FontName','times');
text(5.95,-.2,'6','FontName','times');
text(-.2,2,'2','FontName','times');
text(-.2,4,'4','FontName','times');
%replot the points
points = plot(xoutG(:,1),xoutG(:,2),'rs','MarkerFaceColor','r');
points(1).MarkerSize= 6;

%create the axes
%x axis from 0 to +8.2
[xaxx,xaxy] = ds2nfu([-0.2 8.2], [5.75 5.75]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from 0 to 6.2
[yaxx,yaxy] = ds2nfu([0.0 0.0],[6.1 -.2]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);
text(8.15,-.2,'\itx','FontName','times')
text(-0.2, 6, '\ity','FontName','times')

set(gca,'FontName','times')          %set the plot font to times
set(gca,'FontSize',8)                %set the plot size to 8pt
set(gcf,'Color',[1 1 1]);
