%%
% Scipt to render images with hexagonal pixels
%%
clf
clc
%
s ={[1 0]' ; [0 1]'};

f(1) = figure(1);

% Square pixels
F = imread('PhantomS.png','png');
F = double(F)/double(max(F(:)));

n = size(F,1);
m = size(F,2);

for c=0:(m-1)
    for r=0:(n-1)
        p = c*s{1} + (n-r-1)*s{2};
        v = F(r+1,c+1);
        Sqpix(p,1.0,v);
        %plot(p(1),p(2),'bs','MarkerFaceColor',[v v v],'MarkerSize',20);
    end
end
hold off
axis square
set(f(1),'Position',[1 1 1000 1000])

%%
%% Procedure to draw a square pixel
%%
function A = Sqpix(p,s,l)
xhex=[0.5 -0.5 -0.5  0.5];
yhex=[0.5  0.5 -0.5 -0.5];

patch(xhex+p(1),yhex+p(2),[l l l])
end

