其目的是尽可能忠实地再现图像。两个问题:参数 s 没有被考虑在内;标签的尺寸仍然太小。
\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
vardef card(expr a, c, s) = image(
save rectangle;
path rectangle;
rectangle = unitsquare xscaled 2 cm yscaled 4cm;
draw rectangle rotatedaround((1cm,2cm),a) withcolor c;
label(btex \Huge s etex ,center rectangle) rotatedaround((1cm,2cm),a) withcolor c;
)
enddef;
beginfig(1)
pickup pencircle scaled 4;
color pink;
pink = (3/4, 1/3, 1/3);
draw card(-10, 1/4[red, white], A);
draw card(10 , 1/4[green, white], L) shifted 80 right;
draw card(-10, 1/4[blue, white], E) shifted 160 right;
draw card(10, pink, A) shifted 240 right;
endfig;
\end{mplibcode}
\end{document}
答案1
可能有更好的方法,但这里有一个可行的方法。无论好坏,我都改变了你原来的方法中的几件事(要获得更接近你原来的答案,请参阅编辑历史中的第一个答案)。
- 我不知道是否或者如何在不传递宏中的字符串的情况下完成标签,因此我将标签作为字符串传递,例如“A”。
- 我按照指导
plain.mp
做了标签。这还允许您非常轻松地指定比例(pic1
见下文)。 - 我没有分别旋转矩形和标签,而是将它们画在一起并旋转结果。
编辑:更改为不需要额外的包,请参阅原始的编辑历史graphicx
\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\begin{document}
\begin{mplibcode}
vardef card(expr a, c, s) = image(
save pic,rectangle;
picture pic[];
path rectangle;
rectangle = unitsquare xscaled 2 cm yscaled 4cm;
pic1= s infont defaultfont scaled 4;% change your scale here
pic2=image(
draw rectangle;
draw pic1 shifted (center rectangle-center pic1);
);
draw pic2 rotatedaround((1cm,2cm),a) withcolor c;
)
enddef;
beginfig(1)
pickup pencircle scaled 4;
color pink;
pink = (3/4, 1/3, 1/3);
draw card(-10, 1/4[red, white], "A");
draw card(10 , 1/4[green, white], "L") shifted 80 right;
draw card(-10, 1/4[blue, white], "E") shifted 160 right;
draw card(10, pink, "A") shifted 240 right;
endfig;
\end{mplibcode}
\end{document}
答案2
再来一次...
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{fontspec}
\setmainfont{Arial Rounded MT Bold}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
vardef card(expr rotation, shade, letter) = image(
path rectangle; rectangle = unitsquare shifted (-1/2, -1/2) xscaled 56 yscaled 91 ;
unfill rectangle;
draw rectangle withpen pencircle scaled 4.2;
undraw rectangle withpen pencircle scaled 3 withcolor 1/2[shade, background];
label(textext(letter) scaled 6, origin) withcolor shade;
currentpicture := currentpicture rotated rotation;
) enddef;
beginfig(1);
draw card(normaldeviate + 10, 1/2 red, "A");
draw card(normaldeviate - 10, 1/2 green, "L") shifted 80 right;
draw card(normaldeviate + 10, 1/4[blue, white], "E") shifted 160 right;
draw card(normaldeviate - 10, 1/2[red, blue], "A") shifted 240 right;
endfig;
\end{mplibcode}
\end{document}
笔记
unitsquare
如果你移动它,使它以原点为中心,那么旋转会更容易draw
+undraw
使用较细的笔是获得圆角的有效技巧您可以缩放
picture
返回的textext
一点额外的随机旋转可以改善这种显示