% EXTRA DEMO:   POSITION OF A BICYCLE STEM VS TIME
%
% Program:      spirograph.m
% Written by:   
% For:          EE 311
%               Extra Demo Computer Lab 2
% Date:         7-11-2001
% Purpose:      simulates a childs spirogaph toy
clear all, hold off, clf reset, close all

j=sqrt(-1);
r=input('Enter the radius of the outer circle: ');
s=input('Enter the radius of the inner circle: ');
t=input('Enter the position of the pen in the inner circle: ');
circles=input('Enter the number of times you want to go around the big circle: ');
theta=0:pi/50:2*circles*pi;
z=(r-s)*exp(j*theta)+t*exp(-j*r/s*theta);

% Plot as movie
set(gcf,'DoubleBuffer','on')    % Keep the screen from blinking
plot(r*exp(j*theta))            % Plot the outer circle
hold on
axis square
grid
for i =1:length(z)-1
    plot([z(i), z(i+1)])        % Plot the output of spirograph in really
    pause(.01)                  % small segments
end