改进丑陋的 PSTricks 代码

改进丑陋的 PSTricks 代码

考虑以下代码:

\documentclass{article}

\usepackage{pstricks-add}

\psset{unit = 0.47\psunit, fillstyle = solid}

\begin{document}

\begin{pspicture}(0.5,1)(25,12.7)
\psframe(3,1)(10,10)
\psframe[fillcolor = blue!70](3,1)(10,4)
\rput(6.5,2){Saltvand}
\psframe[fillcolor = red!60](3.5,2)(4,12)
\psframe[fillcolor = gray!60](9,2)(9.5,12)
\psframe[fillcolor = black](1,11.7)(3,12.3)
\psline[linewidth = 3\pslinewidth](2.9,12.23)(3.75,12)
\psline[linewidth = 3\pslinewidth](2.9,11.77)(3.75,12)
\psframe[fillcolor = black](12,11.7)(10,12.3)
\psline[linewidth = 3\pslinewidth](10.1,12.23)(9.25,12)
\psline[linewidth = 3\pslinewidth](10.1,11.77)(9.25,12)
\psframe[fillcolor = gray!80](14,1)(24,9)
\psframe(15,4)(21,8)
\psarc[linewidth = 0.75\pslinewidth](18,5){2}{30}{150}
\multido{\i = 30+40}{4}{%
  \psRelLine[angle = \i, linewidth = 1.5\pslinewidth](18,5)(20.3,5){1}{A}
  \psRelLine[angle = \i, linecolor = white, linewidth = 2.5\pslinewidth](18,5)(19.7,5){1}{A}%
}
\multido{\i = 50+40}{3}{
  \psRelLine[angle = \i, linewidth = 0.75\pslinewidth](18,5)(20.3,5){1}{A}
  \psRelLine[angle = \i, linecolor = white, linewidth = 2\pslinewidth](18,5)(19.7,5){1}{A}%
}
\psline[origin = {18, 5},linewidth = 2\pslinewidth](2.5;120)
\psframe(17,2.4)(19,2.6)
\psframe[fillcolor = black](17.2,2.2)(17.8,2.8)
\rput(16,2.5){\large $=$}
\rput(20,2.5){\large $\sim$}
\pscircle(23,2.7){0.5}
\pscircle(23,2.7){0.2}
\rput(21.8,2.7){\large $-$}
\pscircle(23,4.2){0.5}
\pscircle(23,4.2){0.2}
\rput(21.8,4.2){\large $+$}
\rput(23,1.7){\scriptsize $0$/Jord}
\rput[t](22.5,8){\shortstack[c]{%
  \footnotesize Volt-\strut\\[-0.75ex]
  \footnotesize meter\strut}
}
\psset{fillstyle = none}
\psline(1,12)(0.5,12)(0.5,12.7)(25,12.7)(25,2.7)(23,2.7)
\psline(12,12)(24.5,12)(24.5,4.2)(23,4.2)
\end{pspicture}

\end{document}

输出

输出结果符合我的要求,但代码不太美观。特别是代码\multido写得很糟糕;有人能帮我改进一下吗?

答案1

可以\multido简化为:

\multido{\i=30+40}{4}{\psline[origin={18,5},linewidth=2\pslinewidth](1.75;\i)(2.25;\i)}
\multido{\i=50+40}{3}{\psline[origin={18,5}](1.75;\i)(2.25;\i)}

也许这两个圆圈相同\psRing

\documentclass{article}
\usepackage{pstricks-add}

\psset{unit=0.47cm,fillstyle=solid}

\begin{document}

\begin{pspicture}(0.5,1)(25,12.7)
\psframe(3,1)(10,10)
\psframe[fillcolor = blue!70](3,1)(10,4)
\rput(6.5,2){Saltvand}
\psframe[fillcolor = red!60](3.5,2)(4,12)
\psframe[fillcolor = gray!60](9,2)(9.5,12)
\psframe[fillcolor = black](1,11.7)(3,12.3)
\psline[linewidth = 3\pslinewidth](2.9,12.23)(3.75,12)
\psline[linewidth = 3\pslinewidth](2.9,11.77)(3.75,12)
\psframe[fillcolor = black](12,11.7)(10,12.3)
\psline[linewidth = 3\pslinewidth](10.1,12.23)(9.25,12)
\psline[linewidth = 3\pslinewidth](10.1,11.77)(9.25,12)
\psframe[fillcolor = gray!80](14,1)(24,9)
\psframe(15,4)(21,8)
\psarc[linewidth = 0.75\pslinewidth](18,5){2}{30}{150}
\multido{\i = 30+40}{4}{\psline[origin={18,5},linewidth=2\pslinewidth](1.75;\i)(2.25;\i)}
\multido{\i=50+40}{3}{\psline[origin={18,5}](1.75;\i)(2.25;\i)}
\psline[origin = {18, 5},linewidth = 2\pslinewidth](2.5;120)
\psframe(17,2.4)(19,2.6)
\psframe[fillcolor = black](17.2,2.2)(17.8,2.8)
\rput(16,2.5){\large $=$}
\rput(20,2.5){\large $\sim$}
\psRing(23,2.7){0.5}{0.2}
\rput(21.8,2.7){\large $-$}
\psRing(23,4.2){0.5}{0.2}
\rput(21.8,4.2){\large $+$}
\rput(23,1.7){\scriptsize $0$/Jord}
\rput[t](22.5,8){\shortstack[c]{%
  \footnotesize Volt-\strut\\[-0.75ex]
  \footnotesize meter\strut}}
\psset{fillstyle=none}
\psline(1,12)(0.5,12)(0.5,12.7)(25,12.7)(25,2.7)(23,2.7)
\psline(12,12)(24.5,12)(24.5,4.2)(23,4.2)
\end{pspicture}

\end{document}

相关内容