
% function makegrid(make_element,size,spacing,num_elements_x,num_elements_y)
%
% A function that creates grids of elements.  Examples of use are:
%
% makegrid('plotcircle',200,400,10,10)
% 
% This will call a subfunction plotcircle.m and make a grid of circles,
% 10 x 10, with diameter 200 and center distance 400.
%
% makegrid ('plotsquare',200,400,10,10)
%
% This will call a subfunction plotsquare.m and make a grid of squares, 
% 10 x 10, with width/height 200, and center distance 400.
%
% The parameter "make_element" is a function name.  You can use the
% two functions provided or create your own.  This function must have 
% three parameters: size, X_position, and Y_position.  Such as
% plotsquare() or plotcircle(), it makes a single square or circle at
% X_position,Y_position, size in diameter/height/etc.
% 
% You can make any function you want to create an arbitrary shape, as long
% as it has those three parameters.


function makegrid(make_element,size,spacing,num_elements_x,num_elements_y)

figure;
hold on;

axis([0,(num_elements_x-1)*spacing+size,0,(num_elements_y-1)*spacing+size]);
axis off;
axis equal;

make_element=str2func(make_element);

for X = (size/2):spacing:((num_elements_x-1)*spacing+size/2)
     for Y = (size/2):spacing:((num_elements_y-1)*spacing+size/2)
        make_element(size,X,Y);
     end
 end




