function tcolorfrm.createcolorcircle (const size:integer): Tbitmap;
Var
I,j,x,y:integer;
Radius:integer;
perimeter,arc,degree,step:double;
R,g,b:byte;
Color:tcolor;
Begin
Radius: = round (SIZE/2);
RESULT: = tbitmap.create;
r:=255;
g:=0;
b:=0;
With RESULT do
Begin
Width: = size;
height:= size;
PixelFormat: = Pf24bit;
Canvas.Brush.Color: = RGB (r,g,b);
X: = size + 1;
Y: = round (RADIUS) + 1;
Canvas.fillrect (Rect (Size,round (RADIUS), x, y));
For J: = 0 to size do
Begin
Perimeter: = (size-j) * PI + 1;
Arc: = PERIMETER/6;
Step: = (255 * 6)/perimeter; Color Gradient Step
For I: = 0 to Round (perimeter)-1 do
Begin
Degree: = 360/perimeter * i;
x: = round (cos (degree * pi/180) * (size-j + 1)/2) + radius;//mathematical formula, plus the center point
Y: = round (sin (degree * pi/180) * (size-j + 1)/2) + radius;
if (Degree > 0) and (degree <=) then
Begin
R: = 255;
G: = 0;
B: = Round (step * i);
End
if (Degree >) and (Degree <=) then
Begin
If PERIMETER/3 * (degree-60) > 1.0 Then
R: = 255-round (step * (I-ARC))
Else
R: = 255-round (step * ABS (I-ARC));
G: = 0;
B: = 255;
End
if (Degree >) and (Degree <=) then
Begin
R: = 0;
If PERIMETER/3 * (degree-120) > 1.0 Then
G: = Round (Step * (I-2 * arc))
Else
G: = Round (step * ABS (I-2 * arc));
B: = 255;
End
if (Degree > Degree) and (<=) then
Begin
R: = 0;
G: = 255;
If PERIMETER/3 * (degree-120) > 1.0 Then
B: = 255-round (step * (I-PERIMETER/2))
Else
B: = 255-round (step * ABS (I-PERIMETER/2));
End
if (Degree >) and (Degree <=) then
Begin
If PERIMETER/3 * (degree-240) > 1.0 Then
R: = Round (Step * (I-4 * arc))
Else
R: = Round (step * ABS (I-4 * arc));
G: = 255;
B: = 0;
End
if (Degree >) and (Degree <=) then
Begin
R: = 255;
If PERIMETER/3 * (degree-300) > 1.0 Then
G: = 255-round (Step * (I-5 * arc))
Else
G: = 255-round (step * ABS (I-5 * arc));
B: = 0;
End
Color: = RGB (ROUND (R + (255-R)/size * j), ROUND (G + (255-G)/Size * j), ROUND (B + (255-b)/size * j));
Canvas.Brush.Color: = Color;
To draw a good-looking circle, divide it into four sections to draw
if (degree >= 0) and (degree <=) then
Canvas.fillrect (Rect (x,y,x-2,y-1));
if (Degree >) and (Degree <= 135) Then
Canvas.fillrect (Rect (x,y,x-1,y-2));
if (Degree > 135) and (degree <= 225) Then
Canvas.fillrect (Rect (x,y,x+2,y+1));
if (Degree > 215) and (degree <= 315) Then
Canvas.fillrect (Rect (x,y,x+1,y+2));
if (Degree > 315) and (degree <=) then
Canvas.fillrect (Rect (x,y,x-2,y-1));
End
End
End
End
Delphi code rendering for RGB color loops