我在 Aditya 的推介会正如他在 TeXTalk 中提到的那样。我几乎可以肯定 Aditya 正在使用Metafun
它。
但我想知道如何在 中实现这一点tikz
。方框和箭头的妙处在于它们会随着每个新实例而不断变化。某种随机化正在发生。
答案1
网站上有几处使用 TikZ 手绘线条的参考资料(大部分来自我们的手绘大师打击乐手):
实际上,让形状在每个实例中都发生改变几乎是一件简单的事情,因为这是正常行为,除非你指定种子:参见TikZ:装饰-随机步骤:如何获得两次完全相同的形状?
利用该模块的一个例子oo
:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usepgfmodule{oo}
\usetikzlibrary{calc,positioning,decorations.pathmorphing}
\tikzset{pencil draw/.style={
draw,
decorate,
decoration={random steps,segment length=3mm,amplitude=0.2mm}
}
}
\pgfooclass{module}{
% class attributes
\attribute text;
\attribute text width=2.5cm;
\attribute label;
\attribute width=3cm;
\attribute height=1cm;
% constructor method
\method module() {
}
\method text(#1) {
\pgfooset{text}{#1}
}
\method set text width(#1) {
\pgfooset{text width}{#1}
}
\method set label(#1) {
\pgfooset{label}{#1}
}
\method set width(#1) {
\pgfooset{width}{#1}
}
\method set height(#1) {
\pgfooset{height}{#1}
}
\method draw(#1,#2) {
\node [rectangle,
thick,
pencil draw,
align=center,
text width=\pgfoovalueof{text width},
minimum width=\pgfoovalueof{width},
minimum height=\pgfoovalueof{height},
] (\pgfoovalueof{label}) at (#1,#2) {\pgfoovalueof{text}};
}
\method place(#1) {
\node [rectangle,
thick,
pencil draw,
align=center,
text width=\pgfoovalueof{text width},
minimum width=\pgfoovalueof{width},
minimum height=\pgfoovalueof{height},
#1
] (\pgfoovalueof{label}) {\pgfoovalueof{text}};
}
\method connect(#1,#2) {
\draw[-stealth,pencil draw,thick,decorate,decoration={raise=1mm}] (#1)--(#2);
\draw[-stealth,pencil draw,thick,decorate,decoration={raise=1mm}] (#2)--(#1);
}
% shortcut method to easily set labels, text and draw
% use the \pgfoothis to refer to the current object
\method set and draw(#1,#2,#3,#4) {
\pgfoothis.set label(#1)
\pgfoothis.text(#2)
\pgfoothis.draw(#3,#4)
}
% shortcut method to easily set labels, text and place
% objects
\method set and place(#1,#2,#3) {
\pgfoothis.set label(#1)
\pgfoothis.text(#2)
\pgfoothis.place(#3)
}
% shortcut method to easily set the dimensions
\method set dimensions(#1,#2,#3) {
\pgfoothis.set width(#1)
\pgfoothis.set height(#2)
\pgfoothis.set text width(#3)
}
}
\begin{document}
\begin{frame}{Diagram}
\centering
\only<1-4>{
\begin{tikzpicture}[scale=0.75, transform shape]
\pgfoonew \mod=new module()
\mod.set and draw(reg 1,Region 1,0,0)
\mod.set and place(reg 2,Region 2,right= 3cm of reg 1)
\mod.set and place(contr 1,Controller 1,below= 2cm of reg 1)
\mod.set and place(contr 2,Controller 2,right= 3cm of contr 1)
\mod.connect(reg 1,reg 2)
\mod.connect(reg 1,contr 1)
\mod.connect(reg 2,contr 2)
\mod.connect(contr 1,contr 2)
\node at ($(reg 1)!0.5!(reg 2)-(0,3ex)$) {Interconnect};
\node at ($(contr 1)!0.5!(contr 2)-(0,3ex)$) {Communication};
\end{tikzpicture}
}
\end{frame}
\end{document}
结果: