Coloration graphique animée
J'essaye de démontrer les résultats de ma thèse à travers l'utilisation d'une animation. J'ai construit un MWE pour ce que j'essaie de faire. Essentiellement, j'ai un tas de sommets, dont la couleur de remplissage est donnée par des valeurs RVB échantillonnées pour chaque point de temps que j'ai enregistré dans une table CSV. Je voudrais montrer l'évolution des couleurs des sommets du graphe au fil du temps à travers une animation. Cependant, je ne suis pas vraiment sûr de la meilleure façon de procéder. C'est pourquoi j'aimerais connaître vos opinions / suggestions sur ce sujet. Le code suivant génère un graphique avec trois sommets.
\documentclass{standalone}
\usepackage{tikz,calc}
\begin{document}
\begin{tikzpicture}[align=center,node distance=5cm]
\tikzset{
vertex/.style={draw,circle, line width=3pt,minimum size=1cm,text width=1cm, align=center, font=\Large},
arc/.style={draw, line width = 3pt,-}}
% outer shell
\node[vertex] (V1) at (0,0) {1};
\node[vertex] (V2) [below right of = V1] {2};
\node[vertex] (V3) [above of = V2] {3};
% adjacency
\draw[arc] (V1) -- (V2);
\draw[arc] (V3) -- (V2);
\draw[arc] (V3) -- (V1);
\end{tikzpicture}
\end{document}
De plus, j'ai une table CSV avec les entrées suivantes:
r1,g1,b1,r2,g2,b2,r3,g3,b3
0.8147,0.1576,0.6557,0.7060,0.4387,0.2760,0.7513,0.8407,0.3517
0.9058,0.9706,0.0357,0.0318,0.3816,0.6797,0.2551,0.2543,0.8308
0.1270,0.9572,0.8491,0.2769,0.7655,0.6551,0.5060,0.8143,0.5853
0.9134,0.4854,0.9340,0.0462,0.7952,0.1626,0.6991,0.2435,0.5497
0.6324,0.8003,0.6787,0.0971,0.1869,0.1190,0.8909,0.9293,0.9172
0.0975,0.1419,0.7577,0.8235,0.4898,0.4984,0.9593,0.3500,0.2858
0.2785,0.4218,0.7431,0.6948,0.4456,0.9597,0.5472,0.1966,0.7572
0.5469,0.9157,0.3922,0.3171,0.6463,0.3404,0.1386,0.2511,0.7537
0.9575,0.7922,0.6555,0.9502,0.7094,0.5853,0.1493,0.6160,0.3804
0.9649,0.9595,0.1712,0.0344,0.7547,0.2238,0.2575,0.4733,0.5678
r1, g1, b1 sont les valeurs rgb du nœud 1 et ainsi de suite.
Merci pour votre aide!
Edit: Je voudrais utiliser l'option de remplissage RVB si possible:
\node[...,fill={rgb:red,4;green,2;blue,1}]
Réponses
Cette solution lit les lignes avec des couleurs à partir du fichier au moyen des fonctions LaTeX3. De plus, il utilise la nouvelle commande \multiframebreakpour sortir \multiframeprématurément d'une boucle. ( animate[ 2020/08/29])
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz,calc,animate}
\begin{filecontents}[overwrite,noheader]{vertexcolours.dat}
r1,g1,b1,r2,g2,b2,r3,g3,b3
0.8147,0.1576,0.6557,0.7060,0.4387,0.2760,0.7513,0.8407,0.3517
0.9058,0.9706,0.0357,0.0318,0.3816,0.6797,0.2551,0.2543,0.8308
0.1270,0.9572,0.8491,0.2769,0.7655,0.6551,0.5060,0.8143,0.5853
0.9134,0.4854,0.9340,0.0462,0.7952,0.1626,0.6991,0.2435,0.5497
0.6324,0.8003,0.6787,0.0971,0.1869,0.1190,0.8909,0.9293,0.9172
0.0975,0.1419,0.7577,0.8235,0.4898,0.4984,0.9593,0.3500,0.2858
0.2785,0.4218,0.7431,0.6948,0.4456,0.9597,0.5472,0.1966,0.7572
0.5469,0.9157,0.3922,0.3171,0.6463,0.3404,0.1386,0.2511,0.7537
0.9575,0.7922,0.6555,0.9502,0.7094,0.5853,0.1493,0.6160,0.3804
0.9649,0.9595,0.1712,0.0344,0.7547,0.2238,0.2575,0.4733,0.5678
\end{filecontents}
\usepackage{expl3}
\ExplSyntaxOn
\ior_new:N \l_colours_stream % file descriptor
\seq_new:N \g_colours_seq % sequence var taking colours at a given time
\ior_open:Nn \l_colours_stream {vertexcolours.dat} % open file for reading
\ior_str_get:NN \l_colours_stream \l_tempa_tl % read table header and throw away
\cs_new:Npn\readColours{
\seq_gclear:N \g_colours_seq
\ior_str_get:NNT \l_colours_stream \l_tempa_tl{
\seq_gset_split:NnV \g_colours_seq {,} \l_tempa_tl
}
}
\cs_new:Npn\getColourByIndex#1{
\seq_item:Nn \g_colours_seq {#1}
}
\ExplSyntaxOff
%\makeatletter
%\def\multiframebreak{\global\@anim@mulframecnt=1000}
%\makeatother
\begin{document}
\begin{animateinline}[controls,autoplay,loop]{1}
\readColours%
\multiframe{100}{}{
\begin{tikzpicture}[align=center,node distance=5cm]
\tikzset{
vertex/.style={draw,fill=temp,circle, line width=3pt,minimum size=1cm,text width=1cm, align=center, font=\Large},
arc/.style={draw, line width = 3pt,-}}
% outer shell
\definecolor{temp}{rgb}{\getColourByIndex{1},\getColourByIndex{2},\getColourByIndex{3}}
\node[vertex] (V1) at (0,0) {1};
\definecolor{temp}{rgb}{\getColourByIndex{4},\getColourByIndex{5},\getColourByIndex{6}}
\node[vertex] (V2) [below right of = V1] {2};
\definecolor{temp}{rgb}{\getColourByIndex{7},\getColourByIndex{8},\getColourByIndex{9}}
\node[vertex] (V3) [above of = V2] {3};
% adjacency
\draw[arc] (V1) -- (V2);
\draw[arc] (V3) -- (V2);
\draw[arc] (V3) -- (V1);
\end{tikzpicture}%
\readColours%
\ifthenelse{\equal{\getColourByIndex{1}}{}}{%
\multiframebreak% % no more colours -> break
}{}%
}
\end{animateinline}
\end{document}