function Structures()
% Draws selected color disks against a black square background
close all
figure
set(gcf,'Position',[100 100 800 800])
axis equal off
hold on
fill([1 -1 -1 1],[1 1 -1 -1],'k')

n = 50;
% Create a length n structure array of random disks...
D0 = MakeDisk(MakePoint(0,0), .4*rand,'w');
DrawDisk(D0);
for k=1:n
D(k) = MakeRandomDisk();
end
for k=1:n
DrawDisk(D(k));
end
hold off

function P = MakePoint(x,y)
% x and y are scalars that encode a point (x,y)
% P is a structure with two fields that encodes the point:
% P.x is the x-coordinate of the point
% P.y is the y-coordinate of the point
P = struct('x',x,'y',y);

function D = MakeDisk(C,r,color)
% C is a point
% r is a scalar
% color is one of 'm', 'c', 'b', 'g', 'y', 'r'
% D is a structure with three fields that encodes a colored disk:
% D.C is the center of the disk
% D.r is the radius of the disk
% D.color is the color of the disk
D = struct('C',C,'r',r,'color',color);

function D = MakeRandomDisk()
% D is a disk whose center is randomly located in the square whose
% vertices are (1,1), (-1,1), (-1,-1), (1,1), whose radius is a random
% number between 0.05 and 0.1, and whose color is random
x = -1 + 2*rand(1);
y = -1 + 2*rand(1);
r = .1+.1*rand(1);
s = 'mcbgyr';
color = s(ceil(6*rand(1)));
C = MakePoint(x,y);
D = MakeDisk(C,r,color);

function DrawDisk(D)
% Adds D to the current figure. (Assumes hold toggle on)
theta = linspace(0,2*pi);
xVals = D.C.x + D.r*cos(theta);
yVals = D.C.y + D.r*sin(theta);
fill(xVals,yVals,D.color)