# Pixelized Circle in Tikz

I'm trying to generate something like this in TikZ:

Which can be generated for an arbitrary radius here, which uses this code.

I know how to do it manually in TikZ but it is a real pain. Since I saw in the manual that there is a way to do a for loop in TikZ, there must be a way to generate the pixelated(/minecraft) circle.

Any pointers on how to do this?

A very quick proposal.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray](-5,-5) grid[step=0.25] (5,5);
\foreach \X in {-4.875,-4.625,...,4.875}
{\foreach \Y in {-4.875,-4.625,...,4.875}
{\pgfmathtruncatemacro{\itest}{sqrt(abs(\X*\X+\Y*\Y-4*4))}
\ifnum\itest=0
\draw[gray,fill=red] (\X-0.125,\Y-0.125) rectangle (\X+0.125,\Y+0.125);
\fi}}
\end{tikzpicture}
\end{document}


And something in which you can adjust the parameters. The fudge factor determines the "width" of the circle.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\draw[gray](-xmax,-xmax) grid[step=xstep] (xmax,xmax);
\pgfmathsetmacro{\Xmax}{xmax-xstep/2}
\pgfmathsetmacro{\Xnext}{xmax-3*xstep/2}
\foreach \X in {-\Xmax,-\Xnext,...,\Xmax}
{\foreach \Y in {-\Xmax,-\Xnext,...,\Xmax}
\ifnum\itest=0
\draw[gray,fill=red] (\X-xstep/2,\Y-xstep/2) rectangle (\X+xstep/2,\Y+xstep/2);
\fi}}
\end{tikzpicture}
\end{document}


And this is an attempt of the implementation of the prescription from the web site pointed out by tch.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare
args={2}{insert path={({#1*xstep},{#2*xstep}) rectangle
++(xstep,xstep)}}]
\draw[gray](-xmax,-xmax) grid[step=xstep] (xmax,xmax);