我该如何绘制这些网格?

我该如何绘制这些网格?

在此处输入图片描述

问题没问题,绘制网格应该不是问题,但是如何在箭头开始的方块中绘制模糊的蓝色污渍?

答案1

这可以通过几个\foreach命令来实现,一个\newcommand命令用相同的颜色绘制单元格,一个命令scope重复并旋转绘图。对于模糊的污渍,关键是shadeleandriis 建议的。

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\definecolor{color1}{HTML}{FD6868}
\definecolor{color2}{HTML}{717171}
\definecolor{color3}{HTML}{4C4AFE}
\definecolor{color4}{HTML}{A548A5}

% this draw the cells
\newcommand{\multicell}[5] % x, y, width, height, color
{%
  \foreach\i in {1,...,#3} \foreach\j in {1,...,#4}
  {%
    \draw[fill=#5] (#1+\i-1.5,#2+\j-1.5) rectangle (#1+\i-0.5,#2+\j-0.5);
  }
}

\begin{document}
\begin{tikzpicture}
% Uncomment to show the coordinates
%\foreach\x in {-3,...,3}
%{
%  \node at (\x,-4) {$\x$};
%  \node at (-4,\x) {$\x$};
%}
\foreach\x in {0,1}
{%
  \begin{scope}[shift={(11*\x cm,0 cm)}, rotate=-90*\x]
    \multicell{-3}{-3}{7}{7}{color1}
    \multicell{-1}{ 2}{4}{1}{color2}
    \multicell{-2}{-2}{1}{4}{color2}
    \multicell{-1}{-2}{3}{4}{color3}
    \multicell{ 2}{-2}{1}{4}{white}
    \multicell{ 3}{-2}{1}{4}{color4}
    \multicell{-1}{-3}{4}{1}{color4}
    \foreach\k in {-2,...,1}
    {%
      \shade[inner color=color3] (2,\k) circle (0.4);
      \draw [thick]              (2,\k) -- (4.5,\k);
      \draw [thick,fill=white]   (2,\k) circle (0.05);
      \draw [thick,-latex]       (\k+1,-4.5) -- (\k+1,-3);
    }
  \end{scope}
  % MPI rectangle
  \draw[thick]        (4.5,2) rectangle (6.5,-3);
  \draw[thick,dashed] (5.5,-3) -- (5.5,-4.5);
  \node[text width=0.8cm,align=center] at (5.5,-0.5) {MPI - East to West};
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容