%Chapter 9,  Fig 9.1
%Eric Dubois, updated 2018-12-17
%Draw three instances of a simple color random field in oblique view to be
%arranged vertically
%Required function:  ds2nfu by Michelle Hirsch
clear all, close all;

N=8; %number of colors to use in the random field example
%set the N colors. 
col_mat = [ 0    0.4470    0.7410;
    0.8500    0.3250    0.0980;
    0.9290    0.6940    0.1250;
    0.4940    0.1840    0.5560;
    0.4660    0.6740    0.1880;
    0.3010    0.7450    0.9330;
    0.6350    0.0780    0.1840;
    .8 .8 .8];
%create the plot
for R = 1:3

figure

rectangle('Position',[-5 -2 24 10],'EdgeColor','none')
axis equal
axis off
set(gca,'ydir','reverse'); 

hold on;
par = polyshape([0 4 3 -1], [0 0 2  2]);
for hT = 0:3
    for vT =0:2
        parT = translate(par,[hT*4-vT,vT*2]);
        plot(parT,'FaceColor',col_mat(randi(N),:))
    end
end

%create the axes
%x axis from 0 to 18
[xaxx,xaxy] = ds2nfu([0 18], [6 6]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from 0 to 3.5
[yaxx,yaxy] = ds2nfu([0.0 -3.75],[6 -1.5]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);
text(18,-0.5,'\itx')
text(-4.3, 7, '\ity')

%insert text labels
str_zeta = strcat('$$\zeta_',num2str(R),'$$');
text(-5,3,str_zeta,'Interpreter','latex');
str_f = strcat('$$f_{\zeta_',num2str(R),'}$$');
text(18,3,str_f,'Interpreter','latex');
str_fx0 = strcat('$$f_{\zeta_',num2str(R),'}[\mathbf{x}_0]$$');
text(3.7,3,str_fx0,'Interpreter','latex');

set(gcf,'Color',[1 1 1]);

end