Hello Mr Nigel..
I draw circle onto canvas using Bresenham algorithm.
have 2 question marks spinning on top of my head.
1- drawing to canvas does not adding to undo stack. so undo doesn't work. is there a way to adding in undostack of that direct canvas draw circle operation?
2- It would be awesome draw using brushtool instead of pixel coloring.
how would you do that ?
ImageenVect1.BrushTool.StartPainting
ImageenVect1.BrushTool.AddToPainting
ImageenVect1.BrushTool.EndPainting
seems the only way. but seems too slow and generates filled circle instead of circle.
BresenhamCircle(400, 400, 100, Iv.Layers[0].Bitmap.Canvas, clred);
Iv.Update;
procedure TForm1.BresenhamCircle(CenterX, CenterY, Radius: Integer; Canvas: TCanvas; Color: TColor);
procedure PlotCircle(X, Y, x1, y1: Integer);
begin
Canvas.Pixels[X + x1, Y + y1] := Color;
Canvas.Pixels[X - x1, Y + y1] := Color;
Canvas.Pixels[X + x1, Y - y1] := Color;
Canvas.Pixels[X - x1, Y - y1] := Color;
Canvas.Pixels[X + y1, Y + x1] := Color;
Canvas.Pixels[X - y1, Y + x1] := Color;
Canvas.Pixels[X + y1, Y - x1] := Color;
Canvas.Pixels[X - y1, Y - x1] := Color;
end;
var
X, Y, r: Integer;
x1, y1, p: Integer;
begin
X := CenterX;
Y := CenterY;
r := Radius;
x1 := 0;
y1 := r;
p := 3 - 2 * r;
while (x1 < y1) do
begin
PlotCircle(X, Y, x1, y1);
if (p < 0) then
p := p + 4 * x1 + 6
else
begin
p := p + 4 * (x1 - y1) + 10;
y1 := y1 - 1;
end;
x1 := x1 + 1;
end;
if (x1 = y1) then
PlotCircle(X, Y, x1, y1);
end;