% Shapes.m - Greg Bucks - 10/22/2013
% Description: this script will display a solid square, and open square,
% and a triangle of a user specified dimension,  using *
% Usage: >> Shapes;

% clean up
clear all;
close all;
clc;

% get the sizes for shapes from the user
solid_size = 0;
open_size = 0;
tri_size = 0;
while solid_size <= 0
    solid_size = input('Please enter the length of the side of the solid square: ');
    if solid_size <= 0
        fprintf('Size of the solid square must be greater than 0\n');
    end
end
while open_size <= 0
    open_size = input('Please enter the length of the side of the open square: ');
    if solid_size <= 0
        fprintf('Size of the open square must be greater than 0\n');
    end
end
while tri_size <= 0 || mod(tri_size,2) ~= 1
    tri_size = input('Please enter the length of the base of the triangle: ');
    if tri_size <= 0
        fprintf('Size of the triangle must be greater than 0\n');
    elseif mod(tri_size,2) ~= 1
        fprintf('Size of the triangle must be an odd integer\n');
    end 
end

% display the shapes
% solid square
for row = 1:solid_size
    for col = 1:solid_size
        fprintf('*');
    end
    fprintf('\n');
end
fprintf('\n');
% open square
for row = 1:open_size
    for col = 1:open_size
        if row == 1 || row == open_size || col == 1 || col == open_size
            fprintf('*');
        else
            fprintf(' ');
        end
    end
    fprintf('\n');
end
fprintf('\n');
% triangle
for row = 1:ceil(tri_size/2)
    for col = 1:tri_size
        if col <= (ceil(tri_size/2)-row)
            fprintf(' ');
        elseif col <= (tri_size - (ceil(tri_size/2)-row))
            fprintf('*');
        else
            break;
        end
    end
    fprintf('\n');
end