%Program to synthesize a named color  with red, green and blue circles.
%Set the frame size
H = 500; W = 500;
close all
%Get the color name
colorName = input('What is the color name? ','s');
frameRed = repmat(uint8(0),H,W);
frameGreen = frameRed;
frameBlue = frameRed;
slate = cat(3,frameRed, frameGreen, frameBlue);
colfig = figure('Menubar','none','Name','Colour mixing','NumberTitle','off','Position',[362    87   550   550]);
imshow(slate)
hold on
title(colorName)
%generate the color circles
%prototype circle
radius2 = 100^2;
circle = zeros(201,201);
[X,Y] = meshgrid(1:201);
cen = [101 101];
rad = (X-cen(1)).^2 + (Y-cen(2)).^2;
circle((rad<radius2))=1;
%red circle
red = input('How much red (0-100)? ');
circleRed = uint8(red*2.55*circle);
planeRed = frameRed;
planeRed(25:225,40:240) = circleRed;
slate = cat(3,planeRed, frameGreen, frameBlue);
imshow(slate)
%green circle
green = input('How much green (0-100)? ');
circleGreen = uint8(green*2.55*circle);
planeGreen = frameGreen;
planeGreen(275:475,40:240) = circleGreen;
slate = cat(3,planeRed, planeGreen, frameBlue);
imshow(slate)
%blue circle
blue = input('How much blue (0-100)? ');
circleBlue = uint8(blue*2.55*circle);
planeBlue = frameBlue;
planeBlue(150:350,260:460) = circleBlue;
slate = cat(3,planeRed, planeGreen, planeBlue);
imshow(slate)
%move the circles together
pause
iternum = 50;
vmovR = 125/iternum;
hmovR = 110/iternum;
for iter = 1:iternum
    planeRed = frameRed;
    planeGreen = frameGreen;
    planeBlue = frameBlue;
    edgeRed = round([25 + vmovR*iter 40 + hmovR*iter]);
    planeRed(edgeRed(1):edgeRed(1)+200,edgeRed(2):edgeRed(2)+200) = circleRed;
    edgeGreen = round([275 - vmovR*iter 40 + hmovR*iter]);
    planeGreen(edgeGreen(1):edgeGreen(1)+200,edgeGreen(2):edgeGreen(2)+200) = circleGreen;
    edgeBlue = round([150 260-hmovR*iter]);
    planeBlue(edgeBlue(1):edgeBlue(1)+200,edgeBlue(2):edgeBlue(2)+200) = circleBlue;
    slate = cat(3,planeRed, planeGreen, planeBlue);
    imshow(slate)
    drawnow
end