使用 TikZ 创建 CAPTCHA 和其他奇特的扭曲字母

使用 TikZ 创建 CAPTCHA 和其他奇特的扭曲字母

我尝试将这个短语 (ΔελτιοΥλης) 做得更壮观一些。这是我学生的新闻材料上的标题。事实上,我可以使用 gimp 或图形程序(例如 inscape 或类似程序)来实现这一点。

但我想要的是通过 tikz 对字母进行艺术变形向我的学生展示不使用外部程序即可使用 LaTeX 的可能性。

我的问题: 有没有办法扭曲字母?如何扭曲?

目前这就是我所做的……当然我没有艺术天赋……

在此处输入图片描述

\documentclass[b5paper,svgnames,10pt]{book}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage{color}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\draw[grid,step=0.5cm,gray,very thin] (-1cm,-1cm) grid (9cm,1.5cm);
\node[scale=5.,color =MidnightBlue ] at (0,0) {$\Delta$};
\node[scale=5.,color =MidnightBlue ,rotate=30] at (0.84cm,0.1cm) {$\varepsilon$};
\node[scale=5.,color =MidnightBlue,rotate=-15 ] at (1.3cm,0.0cm) {$\lambda$};
\node[scale=5.,color =MidnightBlue,rotate=+15 ] at (1.95cm,-0.2cm) {$\tau$};
\node[scale=5.,color =MidnightBlue ] at (2.5cm,0) {$\iota$};
\node[scale=5.,color =MidnightBlue ] at (2.6cm,0.4cm) {$'$};
\node[scale=5.,color =MidnightBlue ] at (3.0cm,0) {$o$};
\node[scale=6.,color =MidnightBlue,rotate=-20 ] at (5.3cm,0.08cm) {$\Upsilon$};
\node[scale=5.,color =MidnightBlue ] at (6.cm,-0.2cm) {$\lambda$};
\node[scale=5.,color =MidnightBlue ] at (7.cm,-0.1cm) {$\eta$};
\node[scale=5.,color =MidnightBlue ] at (8.cm,0) {$\varsigma$};
\end{tikzpicture}
\end{document}

答案1

不声称艺术性或任何东西(你可能会,或者可能不会注意到我已经改变了文本:-),同样因为它涉及随机性有时它看起来可以有时则不然:

\documentclass{standalone}
\usepackage{tikz}

\pgfmathdeclarerandomlist{fonts}{{\bf}{\tt}{\rm}{\sf}{\it}{\sl}}

\tikzset{
    distort/.style={
        rotate=rand*10, 
        yslant=rand/3, 
        xslant=rand/3, 
        xscale=1+rand/4,
        yscale=1+rand/4,
        execute at begin node={%
            \pgfmathrandomitem{\newfont}{fonts}\newfont%
        }
    }
}

% Need a special space because inside \node { };
% \ignorespaces and \unskip will remove spaces.
\def\bigspace{\hbox to 1ex{\hfil}}

\begin{document}

\Huge

\begin{tikzpicture}

% The basic idea is to create a node called 0
% then by maintaining indexes \i = 1,2,... and \j = 0,1,...
% it is possible to position the current node (called \i)
% to the previous node (called \j).
\coordinate (0);
\foreach \letter [count=\i, count=\j from 0]in {P,i,g,s, \bigspace  ,m,i,g,h,t, \bigspace ,f,l,y}
    \node [inner sep=0pt, anchor=base west, distort]  at (\j.base east) (\i)
        {\pgfmathrandomitem{\newfont}{fonts}\newfont\letter};

\tikzset{yshift=-0.75in}


% The opacity is stored in an array and accessed
% using the (undocumented) evaluate key.
\foreach \c [evaluate={\o={5,25, 100}[\c-1];}]in {1,...,3} {
    \coordinate (0) at (rand/4, rand/4);
    \foreach \letter [count=\i, count=\j from 0]in {P,i,g,s, \bigspace  ,m,i,g,h,t, \bigspace ,f,l,y}
        \node [inner sep=0pt, anchor=base west, black!\o, distort]  at (\j.base east) (\i) {\letter};
}

\tikzset{yshift=-0.75in}

% In order to get the same randomness (!) the random seed
% can be set to a fixed value. In this case the value is
% selected from the range 1-32768.
\pgfmathrandominteger\seed{1}{32768}
\foreach \c [evaluate={\o={5,25, 100}[\c-1];}]in {1,...,3} {
    \coordinate (0) at (\c*2pt,\c*2pt);
    \pgfmathsetseed{\seed}
    \foreach \letter [count=\i, count=\j from 0]in {P,i,g,s, \bigspace  ,m,i,g,h,t, \bigspace ,f,l,y}
        \node [inner sep=0pt, anchor=base west, black!\o, distort]  at (\j.base east) (\i) {\letter};
}
\end{tikzpicture}

\end{document}

卡帕

编辑:添加了一些随机性,试图使其更加花哨。

答案2

以下是使用 Metapost 和 ConTeXt 的解决方案(不改变字体但随机颜色和缩放):

\starttext
\startMPpage[offset=3mm]

picture lab;

numeric total_width, current_width;

total_width := 0;

for s = "H", "e", "l", "p", "\quad", "Γ", "Δ" :
   lab := textext(s); 
   current_width := xpart (lrcorner lab - llcorner lab);

  for i = 1,3,2 :
   draw lab  rotated (-30 randomized 60) shifted (total_width randomized 5pt, i*6pt randomized 2pt)
      if i = 1 :
        scaled (0.8 randomized 0.2)
        withcolor (0.8 randomized 0.1, 0.8 randomized 0.1, 0.8 randomized 0.2)
      elseif i = 2 :
        scaled (0.8 randomized 0.2)
        withcolor (0.2 randomized 0.1, 0.1 randomized 0.1, 0.8 randomized 0.2)
      else :
        scaled (0.8 randomized 0.2)
        withcolor (0.8 randomized 0.1, 0.8 randomized 0.1, 0.8 randomized 0.2)
      fi;
  endfor

   total_width := total_width + current_width ;
endfor


\stopMPpage

\stoptext

这使

在此处输入图片描述

答案3

没有 PSTricks。

在此处输入图片描述

\documentclass[preview,border=12pt]{standalone}
\usepackage[a0paper]{geometry}
\usepackage[nomessages]{fp}
\usepackage{graphicx}
\usepackage{pgffor}
\FPseed=0
\begin{document}
\foreach \C in {I,a,m,a,p,i,g,.}{%
    \FPrandom\Scale\FPeval\Scale{round(Scale*10+1:2)}
    \FPrandom\Rotate\FPeval\Rotate{round(Rotate*1000:2)}
    \FPrandom\Raise\FPeval\Raise{round(Raise*10:2)}
    \scalebox{\Scale}{\rotatebox{\Rotate}{\raisebox{\Raise pt}{\C}}}%
}%
\end{document}

相关内容