3

Consider the following code:

\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}

output

The output is as I would like it, but the code is not very pretty. Especially the \multido stuff is badly written; can anyone help me improve this?

closed as unclear what you're asking by jubobs, Thorsten, Peter Jansson, Jesse, Guido Jan 7 '14 at 18:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Well, for me the code is pretty. A figure with a lot of pieces ans shapes should be a huge code. – Sigur Jan 7 '14 at 16:24
  • @Sigur You might be right. :) I just don't think it looks very good for some reason. Especially the thing with the display (the \multido stuff) is surely not done the best way. – Svend Tveskæg Jan 7 '14 at 16:31
  • -1 That's not a question; that's code review. – jubobs Jan 7 '14 at 16:41
  • 1
    @SvendTveskæg: write such question to the PSTricks mailing list and nobody will complain .... ;-) – user2478 Jan 7 '14 at 18:53
  • 1
    I think you need to apply OOP-like paradigm to your code to make it easy to read and maintain. For example, it will be better if you create macros \def\Solution for the left container filled with solution and \def\Voltmenter for the right voltemeter. Then in pspicture you use both of them probably with \rput calls to reposition them. What do you think? One of benefits: The used coordinates for one object are independent on those for other objects. – kiss my armpit Jan 7 '14 at 21:41
2

the \multido can be simplified:

\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)}

and maybe the two circles are the same as \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}
  • 1
    I think the improvement is still possible, for example, the obvious one, removing \psset{fillstyle=none} at the third row from above the \end{pspicture}. Unfortunately, I cannot post my answer anymore. – kiss my armpit Jan 7 '14 at 21:52
  • @StiffJokes I can't remove \psset{fillstyle=none} as it is now. (Try to do that and see what happens.) It is unfortunate that you can't post your answer. :( – Svend Tveskæg Jan 8 '14 at 13:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.