delphi绘制爱心代码
时间: 2023-10-06 18:09:58 浏览: 98
画爱心的代码
4星 · 用户满意度95%
以下是 Delphi 中绘制爱心的示例代码:
```delphi
procedure TForm1.DrawHeart(X, Y: Integer; Size: Integer);
var
Points: array[0..6] of TPoint;
Heart: HRGN;
begin
Points[0] := Point(X, Y + Size div 4);
Points[1] := Point(X - Size div 4, Y);
Points[2] := Point(X - Size div 2, Y + Size div 4);
Points[3] := Point(X, Y + Size div 2);
Points[4] := Point(X + Size div 2, Y + Size div 4);
Points[5] := Point(X + Size div 4, Y);
Points[6] := Point(X, Y + Size div 4);
Heart := CreatePolygonRgn(Points, Length(Points), WINDING);
Canvas.Brush.Color := clRed;
FillRgn(Canvas.Handle, Heart, Canvas.Brush.Handle);
DeleteObject(Heart);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DrawHeart(100, 100, 100);
end;
```
以上代码会在画布上绘制一个大小为 100 的红色爱心,位置在 (100, 100) 处。你可以根据自己的需要更改位置和大小。
阅读全文