使用 tikz 轉換單字母

使用 tikz 轉換單字母

我想以一種非常具體的方式轉換扉頁上的一個字母。為了說明我想要實現的效果,我附上了一張圖片。請注意字母 H 的左半部比右半部短,但字母的頂部是水平的。我懷疑我會想使用 tikz 以某種方式扭曲它,但我不確定如何實現這一點。有人可以幫忙嗎?

伸展字母 H

答案1

免責聲明:這不是 TikZ 的答案,但無論如何...

服用Thruston 對有關文本大綱問題的回答作為參考,您可以執行以下操作來獲得變形的 H 字母。這是一個概念證明,因此它僅適用於單個字母,但可以透過進一步調整使其適應完整的單字。

\documentclass{standalone}
\usepackage[latex,shellescape]{gmp}
\begin{document}
\begin{mpost}[name=H]
picture nice;
path P, PP;

nice := image(draw thelabel(\btex H etex,origin));

%Transformation
vardef T(expr p) =
    save x, y;
    x := xpart p; y := ypart p;
%0.01 by guessing. Play with other values
    (x,0.01x*y) 
enddef;

%Assumes a cyclic path
%It can be done better
vardef TT(expr P) =
    T(point 0 of P) 
    .. controls
    T(postcontrol 0 of P) and T(precontrol 1 of P) 
    for j = 1 upto (length P - 1):
        .. T(point j of P) 
        .. controls T(postcontrol j of P) 
            and T(precontrol (j+1) of P) 
    endfor
    .. cycle
enddef;

for i within nice:
    if textual i:
        for j = 1 upto length textpart i:
            string s; s := substring(j-1,j) of textpart i;
            picture g; g := glyph ASCII s of fontpart i scaled 1/10;
            picture r; r := image(
            for x within g:
                picture xx; xx := image(draw g);
%75 is also guessing. Try other values
%Bad filling. It works for the letter H, tho.
                fill TT(pathpart x shifted (llcorner xx - ulcorner xx + 75right)) withcolor
                if greypart x = 1:
                    1
                else:
                    (1,0.843,0)
                fi;
            endfor
            );
            draw r;
        endfor 
    fi
endfor
\end{mpost}\usempost{H}%
\end{document}

在此輸入影像描述

為了進行比較,這是字母 Q 的結果(應用假未填充):

在此輸入影像描述

相關內容