Originally Posted by
Mirage
If you can draw a circle bound, you know all its points. And then you can draw all the needed horizontal lines very fast.
That's exactly what i did. But i now decided to go back to it a little and optimize it. No more overlapped pixels. Also screenshot to let you see the areas it makes with different colors.
Code:
... adding previous code...
procedure DrawVLine(x, y1, y2: longint; color: TColor);
var y: integer;
begin
for y:=y1 to y2 do
form1.Canvas.Pixels[x, y]:=color;
end;
// Optimized fill circle
procedure retro_fill_circle(xc, yc, r: longint; color: TColor);
var x, y, d, y1, y2: longint;
begin
x:=0; y:=r;
d:=1 - r;
y1:=r*7 div 10; // I found this 7/10 ratio just by testing and testing a little...
// It is the Y coordinate where the drawing sections separate
y2:=yc+y1;
y1:=yc-y1;
while x < y do begin
if d < 0 then
d:=d + 2*x + 3
else begin
d:=d + 2*x - 2*y + 5;
dec(y);
end;
DrawVLine(xc - x, yc - y, y1, color); // Top
DrawVLine(xc + x, yc - y, y1, color);
DrawLine(xc - y, xc + y, yc - x, color); // Upper middle
DrawLine(xc - y, xc + y, yc + x, color); // Lower middle
DrawVLine(xc - x, y2, yc + y, color); // Bottom
DrawVLine(xc + x, y2, yc + y, color);
inc(x);
end;
end;
edit: Actually the real ratio might close into sin(45 degree) ~ 0.707. There is 2 pixel-lines overlapped still when drawing with 250 radius. We aren't talking of any significant performance difference though. But if drawing blended pixels you want absolute precision.
Bookmarks