% function visslinger(p, theta)
%
% Teken slinger simulatie.
%
% p         de stapgrootte
% theta     de hoek op elke stap
% voorbeeld:
%    [trk4, yrk4] = rk4('slinger', [0 20], 0.02, [pi/2 5.12]);
%    visslinger(0.02, yrk4(:,1))
% stop met
%    delete(timerfind('Tag', 'Slinger'));
% Dirk Nuyens 2003
function visslinger(p, theta)

delete(timerfind('Tag', 'Slinger'));
T = timer('TimerFcn', {@plotpos, theta, p}, ...
          'Period', p, ...
          'TasksToExecute', length(theta), ...
          'BusyMode', 'drop', ...
          'ExecutionMode', 'fixedRate', ...
          'Tag', 'Slinger');
start(T)


function plotpos(T, Ev, theta, p)

j = get(T, 'TasksExecuted');

figure(30)
clf
hold on;
axis([-1.2 1.2 -1.2 1.2])
axis square
axis off
set(gca, 'XTick', [])
set(gca, 'YTick', [])
set(gca, 'Color', 'none')
title(sprintf('%.2f sec, {\\theta} = %.2f{\\pi} = %.2f', (j-1)*p, theta(j)/pi, theta(j)))
plot([0 -sin(theta(j))], [0 -cos(theta(j))], 'd-')
plot([-sin(theta(j))], [-cos(theta(j))], 'o', 'Markersize', 30)
drawnow

if j == length(theta), stop(T); delete(T); end;
