function [nothing] = draw_pendulum(pendulum_angle)

colorlist = get(gca,'ColorOrder');

l = 0.3; % m
bob = 0.05*l;
dt=0.1;
tsim=0:dt:dt*(length(pendulum_angle)-1);

for kk=1:length(pendulum_angle)
    theta=pendulum_angle(kk);
    theta_out(kk) = theta;
    x_out(kk) = (l-bob)*sin(theta);
    y_out(kk) = -(l-bob)*cos(theta);
    x1(kk) = x_out(kk)+bob*cos(theta);
    y1(kk) = y_out(kk)+bob*sin(theta);
    x2(kk) = l*sin(theta)+bob*cos(theta);
    y2(kk) = -l*cos(theta)+bob*sin(theta);
    x3(kk) = l*sin(theta)-bob*cos(theta);
    y3(kk) = -l*cos(theta)-bob*sin(theta);
    x4(kk) = x_out(kk)-bob*cos(theta);
    y4(kk) = y_out(kk)-bob*sin(theta);
    
end
    
radius = 0.0001;
x_pin = -sqrt(radius):0.00001:sqrt(radius);
y_pin = real(-sqrt(radius-x_pin.^2))+0.005;

fig1 = figure;
plot(x_pin,y_pin,'k')
hold on
plot([x_pin(1)-sqrt(radius) x_pin(end)+sqrt(radius)],[y_pin(1) y_pin(1)],'k')
plot(0,0,'.k','MarkerSize',10)
axis ([-0.5 0.5 -0.5 0.5])
%xticks([-.14:.02:.14])
%xticklabels({'', '-0.12', '', '-0.08', '', '-0.04', '', '0', '', '0.04', '', '0.08', '', '0.12',''});
% axis equal
grid on

dim = [0.2 0.5 0.3 0.3];
v = VideoWriter(sprintf('pendulum_sim_%3.2f',cputime),'MPEG-4');
v.FrameRate = (1/(10*dt));

open(v);

'creating video'
tic
val = 0;
percent_complete = 0;
for kk = 1:length(pendulum_angle)

h1 = plot([0 x_out(kk)],[0 y_out(kk)],'lineWidth',2,'color',colorlist(2,:));
h2 = plot([x4(kk) x1(kk)],[y4(kk) y1(kk)],'lineWidth',1,'color',colorlist(2,:));
h3 = plot([x1(kk) x2(kk)],[y1(kk) y2(kk)],'lineWidth',1,'color',colorlist(2,:));
h4 = plot([x2(kk) x3(kk)],[y2(kk) y3(kk)],'lineWidth',1,'color',colorlist(2,:));
h5 = plot([x3(kk) x4(kk)],[y3(kk) y4(kk)],'lineWidth',1,'color',colorlist(2,:));


 

str = sprintf('t = %f',tsim(kk));
h6 = annotation('textbox',dim,'String',str,'FitBoxToText','on');

pause(0.01)

frame = getframe(fig1);
writeVideo(v,frame);

delete(h1)
delete(h2)
delete(h3)
delete(h4)
delete(h5)
delete(h6)

old_val = mod(val,10);
val = 100*kk/length(tsim);
new_val = mod(val,10);

if new_val < old_val
    percent_complete = percent_complete + 10
end

end
toc

   
close(v)

