创建RGB、CMYK颜色分量圆代码
创建RGB分量圆:
function CreateRGBCircles(const size: INTEGER;
const Rflag, Gflag, Bflag: BOOLEAN): TBitmap;
var
AdjustedSize: INTEGER;
Border: INTEGER;
i, iR, iG, iB: INTEGER;
j, jR, jG, jB: INTEGER;
jOffset: INTEGER;
RadiusSquared: INTEGER;
row: pRGBTripleArray;
function DistanceSquared(const x1, y1, x2, y2: INTEGER): INTEGER;
begin
RESULT := SQR(x1 - x2) + SQR(y1 - y2)
end {两点间距平方};
begin
Border := MulDiv(size, 5, 1000);
AdjustedSize := size - 2 * Border;
RadiusSquared := SQR(MulDiv(AdjustedSize, 2, 6));
iR := Border + MulDiv(AdjustedSize, 2, 6);
iG := Border + MulDiv(AdjustedSize, 3, 6);
iB := Border + MulDiv(AdjustedSize, 4, 6);
//RGB颜色圈内的横坐标
jOffset := ROUND(AdjustedSize * (2 - SQRT(3)) / 12);
jR := jOffset + Border + Round(AdjustedSize * (2 + SQRT(3)) / 6);
jG := jOffset + Border + MulDiv(AdjustedSize, 2, 6);
jB := jR;
//RGB颜色圈内的纵坐标
RESULT := TBitmap.Create;
//输出位图
RESULT.Width := size;
RESULT.Height := size;
RESULT.PixelFormat := pf24bit;
RESULT.Canvas.Brush.Color := RGB(0, 0, 0);
// 黑色背景
RESULT.Canvas.FillRect(RESULT.Canvas.ClipRect);
//填充
for j := 0 to RESULT.Height - 1 do
begin
row := RESULT.Scanline[j];
for i := 0 to RESULT.Width - 1 do
begin
with row[i] do
begin
if Rflag and (DistanceSquared(i, j, iR, jR) < RadiusSquared)
then rgbtRed := 255;
//红色分量为255
if GFlag and (DistanceSquared(i, j, iG, jG) < RadiusSquared)
then rgbtGreen := 255;
//绿色分量为255
if BFlag and (DistanceSquared(i, j, iB, jB) < RadiusSquared)
then rgbtBlue := 255
//蓝色分量为255
end
end
end
end ;
创建CMYK分量圆:
function CreateCMYCircles(const size: INTEGER;
const Cflag, Mflag, Yflag: BOOLEAN): TBitmap;
var
AdjustedSize: INTEGER;
Border: INTEGER;
i, iC, iM, iY: INTEGER;
j, jC, jM, jY: INTEGER;
jOffset: INTEGER;
RadiusSquared: INTEGER;
row: pRGBTripleArray;
function DistanceSquared(const x1, y1, x2, y2: INTEGER): INTEGER;
begin
RESULT := SQR(x1 - x2) + SQR(y1 - y2)
end;
begin
Border := MulDiv(size, 5, 1000);
AdjustedSize := size - 2 * Border;
RadiusSquared := SQR(MulDiv(AdjustedSize, 2, 6));
iC := Border + MulDiv(AdjustedSize, 2, 6);
iM := Border + MulDiv(AdjustedSize, 3, 6);
iY := Border + MulDiv(AdjustedSize, 4, 6);
//CMY颜色圈的点的横坐标
jOffset := ROUND(AdjustedSize * (2 - SQRT(3)) / 12);
jC := jOffset + Border + Round(AdjustedSize * (2 + SQRT(3)) / 6);
jM := jOffset + Border + MulDiv(AdjustedSize, 2, 6);
jY := jC;
//CMY颜色圈的点的纵坐标
RESULT := TBitmap.Create;
RESULT.Width := size;
RESULT.Height := size;
RESULT.PixelFormat := pf24bit;
//创建输出位图
RESULT.Canvas.Brush.Color := RGB(255, 255, 255); // white
RESULT.Canvas.FillRect(RESULT.Canvas.ClipRect);
//白色背景
for j := 0 to RESULT.Height - 1 do
begin
row := RESULT.Scanline[j];
for i := 0 to RESULT.Width - 1 do
begin
with row[i] do
begin
if Cflag and (DistanceSquared(i, j, iC, jC) < RadiusSquared)
then rgbtRed := 0;
//红色分量为0
if MFlag and (DistanceSquared(i, j, iM, jM) < RadiusSquared)
then rgbtGreen := 0;
//绿色分量为0
if YFlag and (DistanceSquared(i, j, iY, jY) < RadiusSquared)
then rgbtBlue := 0;
end //蓝色分量为0
end
end
end;