How to make a square with circles using tikz?

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

enter image description here

\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?

enter image description here

\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}

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}

enter image description here


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.

length=5 and radius=1.5:
v1

length=5 and radius=3:
v2

(orange grid is just to see dimensions).

Tags:

Tikz Pgf