close all; clear; clc;
global debugLevel_01;
global L1;
global L2;
global SUM_L1_L2;

debugLevel_01 = 1;
L1 = 110.0; % Link Length in mm
L2 = 140.0; % Link Length in mm

% hf = figure('color','white');
%
% maximize(hf);
% axis equal
% axis off
SUM_L1_L2 = L1 + L2;

% NOTE 1: The background image size must be accordingly sey

% NOTE 1A: LARGER IMAGE SIZE
%     maximum_x_limit =   ceil(SUM_L1_L2/100)*100;
%     maximum_y_limit =   ceil(SUM_L1_L2/100)*100;
%     minimum_x_limit = - ceil(SUM_L1_L2/100)*100;
%     minimum_y_limit = - ceil(SUM_L1_L2/100)*100;

% NOTE 1B: REDUCED IMAGE SIZE
maximum_x_limit =   SUM_L1_L2;
maximum_y_limit =   SUM_L1_L2;
minimum_x_limit = - SUM_L1_L2;
minimum_y_limit = - SUM_L1_L2;


width  =  abs(minimum_x_limit) + abs(maximum_x_limit); % col
height =  abs(minimum_y_limit) + abs(maximum_y_limit); % row

I = zeros(height, width, 3); % zeros( ROW, COL) : Try zeros(3,5) on command line to clarify doubt

debugLevel_01 = 0;

dy = maximum_y_limit;
for row =  1  : height % for all rows in I
    dx = minimum_x_limit;
    for col =  1  : width % for all cols in I

               switch isReachable( dx, dy )
                   case -1 % Unreachable: Blue Color
                     I(row, col, 1) = 0; I(row, col, 2) = 0; I(row, col, 3) = 1;

                   case -2 % Unreachable: Green Color
                     I(row, col, 1) = 0; I(row, col, 2) = 1; I(row, col, 3) = 0;

                   case -3  % Unreachable: Cyan Color
                     I(row, col, 1) = 0; I(row, col, 2) = 1; I(row, col, 3) = 1;

                   case -4 % Unreachable: Red Color
                     I(row, col, 1) = 1; I(row, col, 2) = 0; I(row, col, 3) = 0;

                   case -5 % Unreachable: Magenta Color
                     I(row, col, 1) = 1; I(row, col, 2) = 0; I(row, col, 3) = 1;

                   case 2 % Reachable: YELLOW Color
                     I(row, col, 1) = 1; I(row, col, 2) = 1; I(row, col, 3) = 0;

                   case 1 % Reachable: WHITE Color
                     I(row, col, 1) = 1; I(row, col, 2) = 1; I(row, col, 3) = 1;
               end
          dx = dx + 1;
    end
    dy = dy - 1;
end

imshow(I);
title('WHITE and YELLOW color shows the Reachable co-ordinates');
saveas(gcf,'output.jpg')

% Will be used as background image for animation, some-time
J=I;       imwrite(J,'background_c0.bmp');
J=I + 0.1; imwrite(J,'background_c1.bmp');
J=I + 0.2; imwrite(J,'background_c2.bmp');
J=I + 0.3; imwrite(J,'background_c3.bmp');
J=I + 0.4; imwrite(J,'background_c4.bmp');
J=I + 0.5; imwrite(J,'background_c5.bmp');
J=I + 0.6; imwrite(J,'background_c6.bmp');
J=I + 0.7; imwrite(J,'background_c7.bmp');
J=I + 0.8; imwrite(J,'background_c8.bmp');
J=I + 0.9; imwrite(J,'background_c9.bmp');