# How to make a square with circles using tikz?

Im trying to make a square like this

but Im not able to do so.

The idea is to make a square an put 4 circles centered in the corners, but I dont know how to make the fill cover all the circle sector down to the border of the square

The MWE is

\documentclass[]{beamer}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray,thick](0,0) rectangle (4,4);
\draw (4,1)[fill=white,thick] arc (90:180:1);
\draw (1,0)[fill=white,thick] arc (0:90:1);
\draw (3,4)[fill=white,thick] arc (180:270:1);
\draw (1,4)[fill=white,thick] arc (360:270:1);
\end{tikzpicture}
\hspace{2cm}
\begin{tikzpicture}
\draw[even odd rule,fill=gray,thick](0,0) rectangle (4,4) (2,2) circle (2cm);
\end{tikzpicture}
\end{document}


I'm not sure, which region of your image you like to fill by gray color. Like the following image? Please advice!

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\draw[fill=gray](0,0) rectangle (4,4);
\draw[fill=white]
(4,1)   arc (90:180:1)  --
(1,0)   arc (0:90:1)    --
(0,3)   arc (270:360:1) --
(3,4)   arc (180:270:1) -- cycle
;
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}


Or you like to have the following inverse coloring like this?

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\draw   (0,0) rectangle (4,4);
\draw[fill=gray!30]
(4,1)   arc (90:180:1)  --
(1,0)   arc (0:90:1)    --
(0,3)   arc (270:360:1) --
(3,4)   arc (180:270:1) -- cycle
;
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

• Either its a good choice, since the color can be any order, I didnt know you could made the fill this way. – riccs_0x Jan 15 at 4:43

Two more options for such a figure. One uses a clipping path while the second draws the rectangle as a node which allows to use the auto clipping property of a path picture command.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[clip](0,0) rectangle (4,4);
\filldraw[fill=gray] (0,0) circle (1cm);
\filldraw[fill=gray] (0,4) circle (1cm);
\filldraw[fill=gray] (4,0) circle (1cm);
\filldraw[fill=gray] (4,4) circle (1cm);
\end{tikzpicture}
%
\begin{tikzpicture}
\node[draw, minimum size=4cm, fill=gray,
path picture={\foreach \i in {north west, north east, south west, south east}
\filldraw[fill=white] (path picture bounding box.\i) circle (1cm);}]{};
\end{tikzpicture}
\end{document}


I understand that you just want the outline of this, so let it be straight but adjustable:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\def\r{1.5} % Radius of corner circles
\def\l{5}   % Square length

\draw[orange,ultra thin] (0,0) grid (\l,\l);

\draw[line width=3pt]
(\l,\r)     arc (90:180:\r)  --
(\r,0)      arc (0:90:\r)    --
(0,\l-\r)   arc (270:360:\r) --
(\l-\r,\l)  arc (180:270:\r) -- cycle
;
\end{tikzpicture}
\end{document}


If you want to play with both \r and \l, you would draw some interesting pictures (especially if you select a radius that is greater than half the square length.

(orange grid is just to see dimensions).

Perhaps someone is interested in a solution with a configurable number of sides.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

%%  Pentagon -------------------
\coordinate (o1) at (0,0);