% Draw random dots in concentric rings

c= input('How many concentric rings? ');
d= input('How many dots per ring? ');

% Set up figure window
close all; figure;
axis equal off
axis([-c c -c c])
hold on

% Put dots in the area between circles with radii rRing and (rRing-1)
for rRing= 1:c
% Draw d dots
for count= 1:d
% Generate random dot location (polar coord.)
theta= randDouble(0, 360);
radius= randDouble(rRing-1, rRing);

% Convert coord from polar to Cartesian
[x, y]= polar2xy(radius, theta);

% Use plot to draw dot
drawColorDot(x, y, rem(rRing,2));
end
pause(0.5)
end

hold off

% Subfunctions

function drawColorDot(x, y, color)
% Draw a dot on at position(x,y). In red if color=0, otherwise blue.

if color == 0
plot(x, y, 'r.', 'markersize',20)
else
plot(x, y, 'b.', 'markersize',20)
end
end