MATLAB: Drawing circles with multi-colored patterns in the annulus

circlespatternsrgb

This code gives me a circle with a green center and red annulus. What's the simplest way to create patterns within the annulus, like those shown below in blue and yellow?
xpix = 912;
ypix = 1140;
rad = 200;
RGB = zeros(ypix,xpix,3,'uint8');
[x,y] = meshgrid(1:xpix,1:ypix);
xc = (xpix+1)/2;
yc = (ypix+1)/2;
r = sqrt((x-xc).^2+(y-yc).^2);
% Center
ii = r <= rad/1.5;
RGB(:,:,2)=255*ii;
% Annulus
ii = r <= rad & ~ii;
RGB(:,:,1)=255*ii;
imshow(RGB);
imwrite(RGB,'filter.bmp');

Best Answer

clc; clear all ;
M = 10000 ;
N = M/4 ; % Four parts here
R1 = 0.5 ;% Radius of circle1
R2 = 1. ; % Radius of circle 2
th = linspace(0,2*pi,M) ; % Angle 0 to 360
% polar coordinates
x1 = R1*cos(th) ; y1 = R1*sin(th) ;
x2 = R2*cos(th) ; y2 = R2*sin(th) ;
%%Arrnage cooridnates into four parts
X1 = reshape(x1,[N,4])' ;
Y1 = reshape(y1,[N,4])' ;
X2 = fliplr(reshape(x2,[N,4])') ;
Y2 = fliplr(reshape(y2,[N,4])' );
% fill color
figure
hold on
for i = 1:4
if mod(i,2)
patch([X1(i,:) X2(i,:)],[Y1(i,:) Y2(i,:)],'r','edgecolor','none')
else
patch([X1(i,:) X2(i,:)],[Y1(i,:) Y2(i,:)],'b','edgecolor','none')
end
end
axis equal