tikz 画一个视力表

文本排版 2019-09-15 01:20  浏览 :1843


主要用到一个随机函数setrand{<minimum>}{<maximum>}{<multiple of>}{<seed>}

有重复代码使用,但是还没找到好的解决方案,希望大神可以提下意见!

使用 xelatex 编译

效果图如下

代码如下

\\documentclass[tikz]{standalone}
\\usepackage{ctex}
\\usepackage{tikz}
\\usetikzlibrary{calc} 
\\usetikzlibrary{shapes.geometric}
\\usepackage{pgfmath}
\\newcommand\\randmin{}
\\newcommand\\randmax{}
\\newcommand\\randmultof{}
\\newcommand\\setrand[4]%
  {\\def\\randmin{#1}%
   \\def\\randmax{#2}%
   \\def\\randmultof{#3}%
   \\pgfmathsetseed{#4}%
  }
\\newcommand\\nextrand
  {\\pgfmathparse{int(int((rnd*(\\randmax-\\randmin+1)+\\randmin)/\\randmultof)*\\randmultof)}%
   \\xdef\\thisrand{\\pgfmathresult}%
  }
\\setmainfont{Arial}
\\begin{document}
\\setrand{0}{720}{90}{180}
\\begin{tikzpicture}
\\begin{scope}
\\fill[fill=gray!20](0,0)circle(112*0.6);
\\fill[fill=white](0,0)circle(110*0.6);
\\end{scope}
\\draw[line width=2.5pt] (0,-3)--(0,3);
\\draw[line width=2.5pt] (3,0)--(-3,0);
\\foreach \\x in {1,2,...,11}
{
\\foreach \\y in {1,2,3,4}
{
\\nextrand  %重新生成一个新的随机数
\\node at (-7.5*\\x+90*\\y:10*0.6) {{\\resizebox{10pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:20*0.6) {{\\resizebox{20pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:30*0.6) {{\\resizebox{30pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:40*0.6) {{\\resizebox{40pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:50*0.6) {{\\resizebox{50pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:60*0.6) {{\\resizebox{60pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:70*0.6) {{\\resizebox{70pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:80*0.6) {{\\resizebox{80pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:90*0.6) {{\\resizebox{90pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
\\nextrand
\\node at (-7.5*\\x+90*\\y:100*0.6) {{\\resizebox{100pt}{!}{{\\rotatebox{\\thisrand}{E}}}}};
}
}
\\foreach \\z in {1,2,3,4}
{
\\node at (90*\\z:10*0.6) {{\\resizebox{10pt}{!}{5.4}}};
\\node at (90*\\z:20*0.6) {{\\resizebox{20pt}{!}{5.3}}};
\\node at (90*\\z:30*0.6) {{\\resizebox{30pt}{!}{5.2}}};
\\node at (90*\\z:40*0.6) {{\\resizebox{40pt}{!}{5.1}}};
\\node at (90*\\z:50*0.6) {{\\resizebox{50pt}{!}{5.0}}};
\\node at (90*\\z:60*0.6) {{\\resizebox{60pt}{!}{4.9}}};
\\node at (90*\\z:70*0.6) {{\\resizebox{70pt}{!}{4.8}}};
\\node at (90*\\z:80*0.6) {{\\resizebox{80pt}{!}{4.7}}};
\\node at (90*\\z:90*0.6) {{\\resizebox{90pt}{!}{4.6}}};
\\node at (90*\\z:100*0.6) {{\\resizebox{100pt}{!}{4.5}}};
}
\\end{tikzpicture}
\\end{document}



发布评论
登录后方可评论!点击登录
全部评论 (1)
咸菜的味道
1楼 · 2019-09-17 14:01

\documentclass[tikz]{standalone} \usepackage{ctex} \usepackage{tikz} \usetikzlibrary{backgrounds} \setmainfont{Arial} \begin{document} \begin{tikzpicture} \draw[line width=2.5pt] (0,-3)--(0,3); \draw[line width=2.5pt] (3,0)--(-3,0); \pgfmathsetseed{666} \def\circlerd{100}%用于计算圆的半径,单位将是 pt \foreach \y[count=\yj from 0] / \s in {1/5.4,2/5.3,3/5.2,4/5.1,5/5.0,6/4.9,7/4.8,8/4.7,9/4.6,10/4.5} { \pgfmathparse{\circlerd +0.5*\y*10+0.5*\yj*10+60+ln(\y)*60} \xdef\circlerd{\pgfmathresult}%第 \y 个圆的半径,单位将是 pt \pgfmathparse{\y*10} \edef\textboxdm{\pgfmathresult pt}% 文字盒子的尺寸 \foreach \x in {0,7.5,...,352.5} { \pgfmathsetmacro{\thisrand}{random(1,4)*90} \pgfmathsetmacro{\isnumposition}{equal(mod(\x,90),0) ? 1 : 0} \ifnum\isnumposition=0% \node at (\x:\circlerd pt) {{\resizebox{\textboxdm}{!}{{\rotatebox{\thisrand}{E}}}}}; \else \node at (\x:\circlerd pt) {{\resizebox{\textboxdm}{!}{\s}}}; \fi } } \begin{scope}[on background layer] \fill[fill=gray!40](0,0)circle(\circlerd pt + 120pt); \fill[fill=white](0,0)circle(\circlerd pt + 100pt); \end{scope} \end{tikzpicture} \end{document} 就想到这么多了