%
% plot10.m
%
% Plot a grid of Lissajous figures. Use equal axis scaling and turn off
% the axes so the plot is cleaner looking. Choose an appropriate phase
% shift between the waves so that the figures are "rounded out".
%
% Matlab-Monkey.com
% 12/30/2014

% tidy-up your workspace
clc         % clear command window
clear       % clear all variables
close all   % close all graphics windows


N = 4;            % Number of plots along x axis
M = 4;            % Number of plots along y axis

for kx = 1:N
    for ky = 1:M
        % The period of the pattern will be 2*pi, unless the two wavenumbers
        % share a common divisor. If they do share a common divisor, then the 
        % period will be reduced by that common factor. Use the greatest 
        % common divisor function gcd().
        period = 2*pi/gcd(kx,ky);
        t = linspace(0,period,1000);

        % figure out the phase shift that "rounds out" the pattern
        phase = ky*period/4;
        x = sin(kx*t);
        y = sin(ky*t + phase);
        
        % plot
        subplot(N, M, (kx-1)*M+ky)
        plot(x,y,'-')
        axis equal
        axis([-1.2 1.2 -1.2 1.2])
        title([num2str(kx) ':' num2str(ky)])
        
        % turn off the axes
        axis off
    end
end

w = 8;      % plot width in inches
h = 8;      % plot height in inches
set(gcf, 'PaperSize', [w h]);  
set(gcf, 'PaperPosition', [0 0 w h]);  
print ('-dpdf','plot10.pdf');
print ('-dpng','html/plot10.png');