Delphi实现RGB色环的代码绘制
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 ; //颜色渐变步长
for i := 0 to round(perimeter) - 1 do
begin
degree := 360 / perimeter * i;
x := round(cos(degree * PI / 180) * (size - j + 1) / 2) + radius;//数学公式,最后加上的是圆心点
y := round(sin(degree * PI / 180) * (size - j + 1) / 2) + radius;
if (degree > 0) and (degree <= 60) then
begin
R := 255;
G := 0;
B := round(step * i);
end;
if (degree > 60) and (degree <= 120) then
begin
if perimeter / 3 / 120 * (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 > 120) and (degree <= 180) then
begin
R := 0;
if perimeter / 3 / 120 * (degree - 120) > 1.0 then
G := round(step * (i - 2 * arc))
else
G := round(step * ABS(i - 2 * arc));
B := 255;
end;
if (degree > 180) and (degree <= 240) then
begin
R := 0;
G := 255;
if perimeter / 3 / 120 * (degree - 120) > 1.0 then
B := 255 - round(step * (i - perimeter / 2))
else
B := 255 - round(step * ABS(i - perimeter / 2));
end;
if (degree > 240) and (degree <= 300) then
begin
if perimeter / 3 / 120 * (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 > 300) and (degree <= 360) then
begin
R := 255;
if perimeter / 3 / 120 * (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;
//为了绘制出来的圆好看,分成四个部分进行绘制
if (degree >= 0) and (degree <= 45) then
Canvas.FillRect(Rect(x,y,x-2,y-1));
if (degree > 45) 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 <= 360) then
Canvas.FillRect(Rect(x,y,x-2,y-1));
end;
end;
end;
end;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~