% Script P3
% Draws a logarithmic spiral.

% Parameters of the spiral:
turnAngle = 65;
numEdges = 400;
spiralColor1 = 'red';
spiralColor2 = 'blue';
% Set up the plot window...
close all
set(0,'defaultfigureposition',[128 64 800 600])
figure
axis equal off
set(gcf,'color','black')
r = floor(numEdges/2);
hold on
% Display the bounding box...
r = floor(numEdges/2);
plot([-r r r -r -r],[-r -r r r -r],'g','linewidth',3)

%%%%%%%%%%%%% Do not alter any thing above this line %%%%%%%%%%%%%%%%%%%%%

% Spiral starts at (0,0)
x_c = 0;
y_c = 0;
for k= 1:numEdges
% Direction of the k-th edge
theta = (k*turnAngle)*(pi/180);
% k-th edge starts at (x_c,y_c) and ends at (x_next,y_next)
x_next = x_c + k*cos(theta);
y_next = y_c + k*sin(theta);
% plot the k-th edge
if rem(k,2)==1
plot([x_c x_next],[y_c y_next],'color',spiralColor1)
else
plot([x_c x_next],[y_c y_next],'color',spiralColor2)
end
% The "start" of the next leg is the "end" of the current leg
x_c = x_next;
y_c = y_next;
end
hold off
title(sprintf('Edges = %d Turn Angle (degrees) = %3d',numEdges,turnAngle),'fontsize',14,'color','cyan')
shg