1

I would like to create the following picture with TikZ. But I have no idea how to do this mathematically; for example, saying that if that condition is met, the rectangle, corresponding to the image, will turn and also get the color.

At the moment, I can only do it manually, that is, manually positioned and filled out.

With node:

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
    \begin{tikzpicture}
        \node[inner sep=7pt] (a) {};
            \fill[orange] (a.north west) -- (a.south west) -- (a.south east) -- cycle;
            \fill[brown] (a.north west) -- (a.north east) -- (a.south east) -- cycle;
    \end{tikzpicture}
\end{document}

With usual options:

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
    \begin{tikzpicture}
        \fill[orange] (0,1) -- (0,0) -- (1,0) -- cycle;
        \fill[brown] (0,1) -- (1,1) -- (1,0) -- cycle;
    \end{tikzpicture}
\end{document}

Here is the image:

Image

(P.S. ignore the „wave“ in the picture – it has to be straight in a line)

2

Here is a proposal: create the elements of the pattern as saveboxes (to decrease compilation time and avoid nesting tikzpictures or a more complicated syntax), and use them in a random way, and also make random rotations by 90 degrees. Easy to generalize.

\documentclass[border=5pt,tikz]{standalone}
\newsavebox{\obbox}
\sbox\obbox{\begin{tikzpicture}%
\fill[orange] (0,1) -- (0,0) -- (1,0) -- cycle;%
\fill[brown] (0,1) -- (1,1) -- (1,0) -- cycle;%
\end{tikzpicture}}
\newsavebox{\owbox}
\sbox\owbox{\begin{tikzpicture}%
\fill[orange] (0,1) -- (0,0) -- (1,0) -- cycle;%
\fill[white] (0,1) -- (1,1) -- (1,0) -- cycle;%
\end{tikzpicture}}
\newsavebox{\bwbox}
\sbox\bwbox{\begin{tikzpicture}%
\fill[brown!60] (0,1) -- (0,0) -- (1,0) -- cycle;%
\fill[white] (0,1) -- (1,1) -- (1,0) -- cycle;%
\end{tikzpicture}}
\newsavebox{\dwbox}
\sbox\dwbox{\begin{tikzpicture}%
\fill[brown!80!black] (0,1) -- (0,0) -- (1,0) -- cycle;%
\fill[white] (0,1) -- (1,1) -- (1,0) -- cycle;%
\end{tikzpicture}}
\newcommand{\drawbox}[1]{\ifcase#1%
\usebox{\obbox}%
\or%
\usebox{\owbox}%
\or%
\usebox{\bwbox}%
\or%
\usebox{\dwbox}%
\fi}
\begin{document}
    \begin{tikzpicture}
    \foreach \X in {1,...,8}
    { \foreach \Y in {1,...,8}
     {\pgfmathtruncatemacro{\randOne}{4*abs(rand)}
     \pgfmathtruncatemacro{\randFlip}{2*abs(rand)}
     \node[rotate={90*\randFlip}] at (\X,\Y) {\drawbox{\randOne}};
     }
     }
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.