procedure TForm1.DrawPicture(ACanvas: TCanvas);

var

r, c, max_r, max_c: Integer;

X, Y: Single;

begin

ACanvas.Brush.Color := clWhite;

ACanvas.FillRect(0, 0, PaintBox1.Width, PaintBox1.Height);

max_c := PaintBox1.Width div WID + 1;

max_r := PaintBox1.Height div WID + 1;

Y := 0;

for r := 0 to max_r do

begin

X := 0;

for c := 0 to max_c do

begin

if Random > 0.5 then

begin

ACanvas.Pen.Width:=2;

// Draw quarter circles in opposing corners

// Draw Top Left quarter circle

ACanvas.Arc(Round(X - RADIUS ), Round(Y - RADIUS), Round(X + RADIUS), Round(Y + RADIUS),

Round(X), Round(Y + RADIUS), Round(X + RADIUS), Round(Y));

// Draw bottom-right quarter circle

ACanvas.Arc(Round(X - RADIUS + RADIUS + RADIUS), Round(Y - RADIUS + RADIUS + RADIUS), Round(X + RADIUS + RADIUS + RADIUS), Round(Y + RADIUS + RADIUS + RADIUS),

Round(X + RADIUS + RADIUS), Round(Y - RADIUS + RADIUS + RADIUS), Round(X - RADIUS + RADIUS + RADIUS), Round(Y + RADIUS + RADIUS ));

end

else

begin

ACanvas.Pen.Width:=2;

// Draw bottom-left quarter circle

ACanvas.Arc(Round(X - RADIUS - RADIUS - RADIUS), Round(Y + RADIUS), Round(X - RADIUS), Round(Y + RADIUS + 2*RADIUS),

Round(X - RADIUS), Round(Y + 2*RADIUS), Round(X - RADIUS - RADIUS), Round(Y + RADIUS));

// Draw top-right quarter circle

ACanvas.Arc(Round(X - RADIUS), Round(Y - RADIUS), Round(X + RADIUS), Round(Y + RADIUS),

Round(X - RADIUS), Round(Y), Round(X), Round(Y + RADIUS));

end;

X := X + WID;

end;

Y := Y + WID;

end;

if chkFillIt.Checked then

begin

// Flood areas

Y := RADIUS;

for r := 0 to max_r do

begin

X := RADIUS;

for c := 0 to max_c do

begin

if ACanvas.Pixels[Round(X), Round(Y)] = clWhite then

FloodAtPoint(ACanvas, X, Y);

X := X + WID;

end;

Y := Y + WID;

end;

end;

end;