自定义线帽来模拟 TikZ 中的墨迹线

自定义线帽来模拟 TikZ 中的墨迹线

寻找一种方法来添加自定义线帽(略微球状),就像在真实纸张上画线时所得到的那样。在此处输入图片描述

答案1

可以添加这样的箭头提示吗?当然可以。我确定我的建议是有史以来最好的墨水提示吗?绝对不是。但是,这应该可以让您了解如何接近“有史以来最好的墨水提示”。;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}

\pgfdeclarearrow{
  name=ink,
  parameters= {\the\pgfarrowlength},  
  setup code={
   \pgfarrowssettipend{0pt}
   \pgfarrowssetlineend{-\pgfarrowlength}
   \pgfarrowlinewidth=\pgflinewidth
   \pgfarrowssavethe\pgfarrowlength
  },
  drawing code={
   \pgfpathmoveto{\pgfpoint{-\pgfarrowlength}{0.5\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.75\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{-0.01\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{0pt}{0pt}}
   \pgfpathcurveto{\pgfpoint{-0.01\pgfarrowlength}{-0.5\pgflinewidth}}{%
   \pgfpoint{-0.05\pgfarrowlength}{-0.95\pgflinewidth}}{%
   \pgfpoint{-0.2\pgfarrowlength}{-0.9\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.3\pgfarrowlength}{-0.8\pgflinewidth}}{%
   \pgfpoint{-0.6\pgfarrowlength}{-0.55\pgflinewidth}}{%
   \pgfpoint{-01\pgfarrowlength}{-0.5\pgflinewidth}}
   \pgfusepathqfill
  },
  defaults = { length = 12pt }
}
\begin{document}
\begin{tikzpicture}
\draw [line width=1mm,{ink[bend]}-{ink[bend]},blue!80!black] (0,0) to [bend left] (3,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者,如果您希望有更明显的提示,也可以这样做。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}

\pgfdeclarearrow{
  name=ink,
  parameters= {\the\pgfarrowlength},  
  setup code={
   \pgfarrowssettipend{0pt}
   \pgfarrowssetlineend{-\pgfarrowlength}
   \pgfarrowlinewidth=\pgflinewidth
   \pgfarrowssavethe\pgfarrowlength
  },
  drawing code={
   \pgfpathmoveto{\pgfpoint{-\pgfarrowlength}{0.5\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.75\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{-0.01\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{0pt}{0pt}}
   \pgfpathcurveto{\pgfpoint{-0.01\pgfarrowlength}{-0.5\pgflinewidth}}{%
   \pgfpoint{-0.2\pgfarrowlength}{-1.35\pgflinewidth}}{%
   \pgfpoint{-0.3\pgfarrowlength}{-1.1\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.4\pgfarrowlength}{-0.8\pgflinewidth}}{%
   \pgfpoint{-0.6\pgfarrowlength}{-0.55\pgflinewidth}}{%
   \pgfpoint{-01\pgfarrowlength}{-0.5\pgflinewidth}}
   \pgfusepathqfill
  },
  defaults = { length = 12pt }
}
\begin{document}
\begin{tikzpicture}
\draw [line width=1mm,{ink[bend]}-{ink[bend]},blue!80!black] (0,0) to [bend left] (3,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

并且还可以添加一些随机性。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}

\pgfdeclarearrow{
  name=ink,
  parameters= {\the\pgfarrowlength},  
  setup code={
   \pgfarrowssettipend{0pt}
   \pgfarrowssetlineend{-\pgfarrowlength}
   \pgfarrowlinewidth=\pgflinewidth
   \pgfarrowssavethe\pgfarrowlength
  },
  drawing code={
   \pgfpathmoveto{\pgfpoint{-\pgfarrowlength}{0.5\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.75\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{-0.01\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{0pt}{0pt}}
   \pgfpathcurveto{\pgfpoint{-0.01\pgfarrowlength}{-0.5\pgflinewidth}}{%
   \pgfpoint{-0.2\pgfarrowlength}{-(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-0.3\pgfarrowlength}{-0.8*(1+0.3*rnd)*\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.4\pgfarrowlength}{-0.6*(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-0.6\pgfarrowlength}{-0.3*(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-1\pgfarrowlength}{-0.5\pgflinewidth}}
   \pgfusepathqfill
  },
  defaults = { length = 12pt }
}
\begin{document}
\begin{tikzpicture}
\draw [line width=1mm,{ink[bend]}-{ink[bend]},blue!80!black] (0,0) to [bend left] (3,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

奖金:一些快速而肮脏的“墨迹”字母。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{positioning}
\pgfdeclarearrow{
  name=ink,
  parameters= {\the\pgfarrowlength},  
  setup code={
   \pgfarrowssettipend{0pt}
   \pgfarrowssetlineend{-\pgfarrowlength}
   \pgfarrowlinewidth=\pgflinewidth
   \pgfarrowssavethe\pgfarrowlength
  },
  drawing code={
   \pgfpathmoveto{\pgfpoint{-\pgfarrowlength}{0.5\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.75\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{-0.01\pgfarrowlength}{0.6\pgflinewidth}}{%
   \pgfpoint{0pt}{0pt}}
   \pgfpathcurveto{\pgfpoint{-0.01\pgfarrowlength}{-0.5\pgflinewidth}}{%
   \pgfpoint{-0.2\pgfarrowlength}{-(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-0.3\pgfarrowlength}{-0.8*(1+0.3*rnd)*\pgflinewidth}}
   \pgfpathcurveto{\pgfpoint{-0.4\pgfarrowlength}{-0.6*(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-0.6\pgfarrowlength}{-0.3*(1+0.3*rnd)*\pgflinewidth}}{%
   \pgfpoint{-1\pgfarrowlength}{-0.5\pgflinewidth}}
   \pgfusepathqfill
  },
  defaults = { length = 12pt }
}
\begin{document}
\tikzset{pics/.cd,
  A/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,-0.55) -- (0.3,0.4) -- (0.6,-0.55);
  \draw[line width=5](0.1,1/3-0.45) --
  (0.5,1/3-0.45);
  \path (0.7,0);}},
  B/.style={code={\draw[line width=5] (0,-0.45) -- (0,0.45)
  to[out=0,in=0,looseness=2.5]  (0,0)  to[out=0,in=0,looseness=3] cycle;}},
  C/.style={code={\draw[line width=5,-{ink[bend]}]
   (0,0) to[out=90,in=110,looseness=2]  (0.5,0.25);
   \draw[line width=5,-{ink[bend]}](0,0) to[out=-90,in=-110,looseness=2]  (0.5,-0.25);
   \path (0.7,0);}},
  D/.style={code={\draw[line width=5] (0,-0.45) -- (0,0.45) 
  to[out=0,in=0,looseness=2.25]   cycle;
  \path (0.7,0);}},
  E/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0.5,-0.45) --(0,-0.45) -- (0,0.45)  -- (0.5,0.45);
  \draw[line width=5,-{ink[bend]}] (0,0) -- (0.5,0);
  \path (0.7,0);}},
  F/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,-0.45) -- (0,0.45)  -- (0.5,0.45);
  \draw[line width=5,-{ink[bend]}] (0,0) -- (0.5,0);
  \path (0.7,0);}},
  G/.style={code={\draw[line width=5,-{ink[bend]}]
   (0,0) to[out=90,in=110,looseness=2]  (0.5,0.25);
   \draw[line width=5] (0,0) to[out=-90,in=-110,looseness=2]  
   (0.5,-0.25);
   \draw[line width=5,-{ink[bend]}] (0.54,-0.25) to (0.3,-0.25);
   \path (0.7,0);}},
  H/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,-0.5) -- (0,0.5);  
  \draw[line width=5,{ink[bend]}-{ink[bend]}] (0.5,-0.5) -- (0.5,0.5);
  \draw[line width=5] (0,0) -- (0.5,0);
  \path (0.7,0);}},
  I/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,-0.45) -- (0,0.45);
  \path (0.25,0);}},
  J/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0.2,0.45) -- (0.2,-0.35) to[out=-90,in=0]
  (0.1,-0.45) to[out=180,in=-90] (0,-0.35);
  \path (0.45,0);}},
  K/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,-0.45) -- (0,0.45); 
  \draw[line width=5,{ink[bend]}-{ink[bend]}] (0.4,0.45) -- (0.02,0) --  (0.4,-0.45);
  \path (0.6,0);}},
  L/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,0.5) -- (0,-0.45) -- (0.4,-0.45);
  \path (0.6,0);}},
  M/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,-0.45) -- (0,0.45) -- 
  (0.3,0.25) -- (0.6,0.45) -- (0.6,-0.45);
  \path (0.8,0);}},
  N/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,-0.45) -- (0,0.45) -- (0.6,-0.4) --
  (0.6,0.45);
  \path (0.8,0);}},
  O/.style={code={\draw[line width=5] (0.3,0) circle(0.3 and 0.48);
  \path (0.8,0);}},
  P/.style={code={\draw[line width=5,{ink[bend]}-] (0,-0.45) -- (0,0.45) 
  to[out=0,in=0,looseness=2.5]  (0,0);
  \path (0.6,0);}},
  Q/.style={code={\draw[line width=5] 
  (0.3,0) circle(0.3 and 0.48);
  \draw[line width=5,{ink[bend]}-{ink[bend]}](0.35,-0.25) -- (0.6,-0.45);
  \path (0.8,0);}},
  R/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,-0.45) -- (0,0.45) 
  to[out=0,in=0,looseness=2.5]  (0.05,0) -- (0.4,-0.45);
  \path (0.6,0);}},
  S/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0.5,0.4)  
  to[out=160,in=165,looseness=2]  (0.3,0)  
  to[out=-15,in=-20,looseness=2] (0.1,-0.4);
  \path (0.65,0);}},
  T/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0.35,-0.45) -- (0.35,0.45) (0,0.45) -- (0.7,0.45);
  \path (0.85,0);}},
  U/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,0.5) -- (0,0) to[out=-90,in=-90,looseness=2.5]
  (0.6,0) -- (0.6,0.5);
  \path (0.8,0);}},
  V/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,0.5) -- (0.3,-0.4) -- (0.6,0.5);
  \path (0.8,0);}},
  W/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,0.45) -- (0.3,-0.4) -- (0.45,-0.1)
  -- (0.6,-0.4) -- (0.9,0.45);
  \path (1.1,0);}},
  X/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,0.45) -- (0.6,-0.45);
   \draw[line width=5,{ink[bend]}-{ink[bend]}] (0.6,0.45)
  -- (0,-0.45);
  \path (0.8,0);}},
  Y/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] 
  (0,0.45) -- (0.3,0);  
  \draw[line width=5,{ink[bend]}-{ink[bend]}] (0.6,0.45)
  -- (0,-0.45);
  \path (0.8,0);}},
  Z/.style={code={\draw[line width=5,{ink[bend]}-{ink[bend]}] (0,0.45) --(0.6,0.45) -- (0,-0.45)  
  -- (0.6,-0.45);
  \path (0.8,0);}},
  space/.style={code={\path (0,0) (0.2,0);}},
}
\begin{tikzpicture}[blue!80!black]
\pic[local bounding box=box1,scale=2] at (0,0) {A};
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(\Y+1)}] in {B,...,Z}
{\edef\temp{\noexpand\pic[right=0mm of box\Y,local bounding box=box\Z,scale=2]
{\X};}
\temp}
\end{tikzpicture}
\end{document}

在此处输入图片描述

(是的,显然这些字体不如专用字体漂亮。但是,我们可以对它们进行非线性变换,例如这件令人印象深刻的杰作。我把这个应用程序留到另一天再讲。此外,因为箭头和非线性变换需要一些额外的工作

相关内容