% Script nestedStars
% Draws a sequence of nested stars. The first one has radius 1 and
% is magenta.
% Thereafter, the stars alternate in color: yellow, magenta,
% yellow, magenta, etc. Each star has radius that is smaller by
% a factor 1.2 than the radius of the previous star. The process
% continues until the radius is <= .1.

close all
figure
axis equal off
hold on

for c= 0:2:8
% Draw background: s-by-s black square centered at (x,y)
x=c; y=c; % square centered at origin
s = 2.1;
DrawRect(x-s/2,y-s/2,s,s,'k')

% Sequence of stars...
% The radius of the kth star is stored in r...
r = 1; k = 1; rSmallest=.1;
rScale= .8; % Scaling for radius of each subsequent star
while r >= rSmallest
% Draw kth star
if rem(k,2)==1
% Odd-indexed stars are magenta...
DrawStar(x,y,r,'m')
else
% Even indexed stars are yellow...
DrawStar(x,y,r,'y')
end
% Updates for next iteration
r = r*rScale;
k = k+1;
end
end

hold off
shg