function linearRGB = makegray44(average, dev)
% rgb = makegray44(average, deviation)
%
% Creates an array of 44 colormap values containing a set of
% colors that average out to the average value supplied by the 
% caller.
%
% dev specifies the maximum deviation (in terms of RGB units)
% of each color from the average value.
%
% KLY 98

redsum = 0; greensum = 0; bluesum = 0;
linearRGB = zeros(44,3);

% Generate random surrounding squares
for i=1:44
  red = random(dev) + average;
  green = random(dev) + average;
  blue = random(dev) + average;
  
  redsum = redsum + red;
  greensum = greensum + green;
  bluesum = bluesum + blue;
  
  linearRGB(i,:) = [red green blue];
end

avgRed = redsum/44;
avgGreen = greensum/44;
avgBlue = bluesum/44;

linearRGB(:,1) = linearRGB(:,1) * average/avgRed;
linearRGB(:,2) = linearRGB(:,2) * average/avgGreen;
linearRGB(:,3) = linearRGB(:,3) * average/avgBlue;


