Two rotated squares with TIKZ

I am not sure if I would use graph drawing for this. You seem to know very well how the result should look like, i.e. I do not see the need for a layout algorithm. A very simpleminded macro of the type you suggest is the following. (Fixed colors, modulos can be tricky. ;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\newcommand{\mymacro}[1]{
\begin{tikzpicture}
\pgfmathparse{\mycolors[1]}
\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,\pgfmathresult](square1){};
\pgfmathparse{\mycolors[0]}
\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,rotate=45,\pgfmathresult]
(square0){};
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(mod(\Y+1,2))},
evaluate=\Y as \V using {int((\Y+1)/2)}] in {#1}
{\ifnum\Y=9
 \pgfmathsetmacro{\mycolor}{\mycolors[2]}
 \ifnum\X=1
  \filldraw[\mycolor] (0,0) circle (3mm);
 \else
  \draw[thick,fill=white,draw=\mycolor] (0,0) circle (3mm);
 \fi
\else
 \pgfmathsetmacro{\mycolor}{\mycolors[\Z]}
 \ifnum\X=1
  \filldraw[\mycolor] (square\Z.corner \V) circle (3mm);
 \else
  \draw[thick,fill=white,draw=\mycolor] (square\Z.corner \V) circle (3mm);
 \fi
\fi}
\end{tikzpicture}
}
\xdef\mycolors{{"black","red","cyan"}}
\mymacro{1,0,1,1,0,1,1,1,0}
\end{document}

enter image description here

The 0 and 1 entries determine if a given circle is filled, the 9th entry is the dot in the middle. The colors are stored in the \mycolors array.


Here is a simple way to draw.

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[thick]
\def\a{2}
\def\r{.5}
\fill[cyan] (0,0) circle(\r);

\begin{scope}[rotate=-135]
\draw[gray] (-\a,-\a) rectangle (\a,\a);
\filldraw (\a,-\a) circle(\r);
\filldraw (-\a,\a) circle(\r);
\filldraw (-\a,-\a) circle(\r);
\filldraw (\a,\a) circle(\r);
\end{scope}

\draw[red] (-\a,-\a) rectangle (\a,\a);
\filldraw[red] (\a,-\a) circle(\r);
\filldraw[red] (\a,\a) circle(\r);
\filldraw[red] (-\a,-\a) circle(\r);
\draw[red,fill=white] (-\a,\a) circle(\r);
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf