运行的效果如上图所示,具体使用看各位要怎么使用了。它可以做一个颜色获取。比较直观使用。 新建立 Fmx Application 程序,然后放入一个 TCircle 控件,同时添加上System.UIConsts 单元,因为 MakeColor 函数用到了此单元,然后写下如下代码可以实现。
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
Circle1: TCircle;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses
System.UIConsts;
function CreateColorCircle(const ASize: integer): TBitmap;
var
i, j, x, y: integer;
radius: integer;
perimeter, arc, degree, step: double;
R, G, B: byte; color: TColor; vBitMapData: TBitmapData;
begin
radius := round(ASize / 2);
Result := TBitmap.Create;
R := 255;
G := 0;
B := 0;
Result.width := ASize;
Result.height := ASize;
Result.Canvas.Clear(MakeColor(R, G, B));
x := ASize + 1;
y := round(radius) + 1;
Try
RESULT.Map(TMapAccess.maWrite, vBitMapData);
for j := 0 to ASize do begin
perimeter := (ASize - j) * PI + 1;
for i := 0 to round(perimeter) - 1 do begin
degree := 360 / perimeter * i;
x := round(cos(degree * PI / 180) * (ASize - j + 1) / 2) + radius;
// 数学公式,最后加上的是圆心点
y := round(sin(degree * PI / 180) * (ASize - 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 := MakeColor(round(R + (255 - R) / ASize * j), Round(G + (255 - G) / ASize * j), round(B + (255 - B) / ASize * j));
// 为了绘制出来的圆好看,分成四个部分进行绘制
if (degree >= 0) and (degree <= 45) then
vBitMapData.SetPixel(x - 2, y - 1, color);
if (degree > 45) and (degree <= 135) then
vBitMapData.SetPixel(x - 1, y - 2, color);
if (degree > 135) and (degree <= 225) then
vBitMapData.SetPixel(x + 2, y + 1, color);
if (degree > 215) and (degree <= 315) then
vBitMapData.SetPixel(x + 1, y + 2, color);
if (degree > 315) and (degree <= 360) then
vBitMapData.SetPixel(x - 2, y - 1, color);
end;
end;
Finally
Result.Unmap(vBitMapData);
End;
end;
// 调用方式
procedure TForm1.FormCreate(Sender: TObject);
begin
Circle1.Fill.Kind:= TBrushKind.bkBitmap;
Circle1.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch;
Circle1.Fill.Bitmap.Bitmap.Assign( CreateColorCircle(Trunc(Circle1.Width)) );
end;
end.
// 来原:打工的程序员
Add new comment