I'd like to use arrays in tikzmath. I'd like to be able to manually define an array, with the equivalent of the python code myarray = [1,0,0,1,1], and I also would like to be able to access it in tikzmath, using something like myarray[3] as well as modify it, using something like myarray[4] = 42. I found two ways to deal with arrays, but each method has a problem.
The first one (see my MWE) is interesting because it lets me define arrays on the fly, but I don't know how to manually initialize this array using one line, without using a loop to compute the value.
The second solution I found has the opposite problem: I can define an array in a one-line manner, but then access it in tikzmath is difficult, and I need to use crazy structures like:
\pgfmathparse{\myarray[\s]}
\edef\val{\pgfmathresult}
While I'd like to use directly \myarray[\s] in the tikzmath code.
Do you know what is the best way to create an array that you can easily access and modify in tikzmath, and such that if needed I can specify the initial value in a single line command?
Thanks!
MWE:
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
%%% FIRST METHOD
\begin{tikzpicture}
\tikzmath{
\n = 5;
% Works, but one problem: how to manually choose the values
% without using a loop?
int \i;
for \i in {1,...,\n}{
\myarray{\i} = mod(\i,2);
};
% Display
for \i in {1,...,\n}{
if \myarray{\i} == 1 then { \ccolor = "green!30";}
else { \ccolor = "blue!30"; };
{\node[draw,circle,fill=\ccolor] at ({90+360/\n * (\i-1)}:2cm) {$\i$};};
};
}
\end{tikzpicture}
%%% SECOND METHOD
\begin{tikzpicture}
\def\n{5}
\def\myarray{{42,1,0,1,1,0}}
\foreach \s in {1,...,\n}
{
%%% Works but not really easy to read/write, and is not inside the
%%% tikzmath code.
% \pgfmathparse{\myarray[\s]}
% \edef\val{\pgfmathresult}
% \tikzmath{ if \val == 1 then { \ccolor = "green!30"; }
%%% Does not work, no idea why
\tikzmath{ if \myarray[\s] == 1 then { \ccolor = "green!30"; }
else { \ccolor = "blue!30";};
}
\node[draw,circle,fill=\ccolor] at ({90+360/\n * (\s-1)}:2cm) {$\s$};
}
\end{tikzpicture}
\end{document}



