constructor TCircle.Create(ACenter: TPoint; ARadius: Integer);
begin
FCenter:=ACenter;
FRadius:=ARadius;
end;
destructor TCircle.Destroy;
begin
inherited;
end;
procedure TCircle.Draw(ACanvas: TCanvas);
var
PenColor:TColor;
begin
with ACanvas do
begin
PenColor:=Pen.Color;
Pen.Color:=FColor;
Brush.Style:=bsClear;
Pixels[FCenter.X,FCenter.Y]:=clRed;
Ellipse(FCenter.X-FRadius,FCenter.Y-FRadius,FCenter.X+FRadius,FCenter.Y+FRadius);
Pen.Color:=PenColor;
end;
end;
end.
使用如下:
procedure TForm1.Button1Click(Sender: TObject);
var
C:TCircle;
begin
C:=TCircle.Create(Point(50,50),100);
try
C.Draw(PaintBox1.Canvas);
finally
C.Free;
end;
end;
过一点同半径的圆有很多,如果是确定的一个,point(x,y)就是圆心了(我理解),
procedure draw(canvas:tcanvas;r,x,y,from ,tocorner:integer );
var
i:integer;
v:extended;
const
pi=3.1415;
begin
v:=pi/180;
for i:=from to tocorner-1 do
begin
canvas.moveto(x+round(r*sin(i*v)),y+round(r*cos(i*v)));
canvas.lineto(x+round(r*sin((i+1)*v)),y+round(r*cos((i+1)*v)));