
나는 애니메이션을 사용하여 내 논문의 결과를 보여주려고 노력하고 있습니다. 나는 내가 하려는 일을 위해 MWE를 구축했습니다. 기본적으로 CSV 테이블 내에 기록한 모든 시점에 대해 샘플링된 RGB 값으로 채우기 색상이 제공되는 여러 정점이 있습니다. 시간에 따른 그래프 정점의 색상 변화를 애니메이션을 통해 보여주고 싶습니다. 그러나 나는 그것에 대해 가장 좋은 방법을 확신하지 못합니다. 그렇기 때문에 이 주제에 대한 귀하의 의견/제안을 듣고 싶습니다. 다음 코드는 세 개의 꼭짓점이 있는 그래프를 생성합니다.
\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}
또한 다음 항목이 포함된 테이블 CSV 테이블이 있습니다.
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은 노드 1의 rgb 값입니다.
모든 도움에 감사드립니다!
편집: 가능하다면 RGB 채우기 옵션을 사용하고 싶습니다.
\node[...,fill={rgb:red,4;green,2;blue,1}]
답변1
이 솔루션은 LaTeX3 함수를 사용하여 파일에서 색상이 있는 줄을 읽습니다. 또한 루프를 조기에 \multiframebreak
중단하기 위해 새로운 명령을 사용합니다 \multiframe
. ( 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}