2

Could you rewrite the looping part just with nested PostScript ifelse operators?

\documentclass[pstricks,border=1cm]{standalone}

\makeatletter
\def\scale{%
    \psline(100,0)
    \foreach \x in {0,10,...,100}{%
        \pst@mod\x{100}\rem
        \ifnum\rem=0
            \psline(\x,-18)(\x,18)
        \else
            \psline(!\x\space dup 50 mod 0 ne {-3} {-9} ifelse)(!\x\space dup 50 mod 0 ne {3} {9} ifelse)
        \fi}%
}
\makeatother    


\begin{document}
\psset{unit=1mm}
\pspicture(0,-20)(100,20)
    \scale
\endpspicture
\end{document}

enter image description here

4
\documentclass[pstricks,border=1cm]{standalone}

\def\scale{%
  \psline[arrows=|-|,tbarsize=36](100,0)%
  \foreach \x in {10,20,...,90}{%
    \psline(!\x\space dup 50 mod 0 eq {-9}{-3} ifelse)%
           (!\x\space dup 50 mod 0 eq {9}{3} ifelse)}%
}
\begin{document}
    \psset{unit=1mm}
    \pspicture(0,-20)(100,20)
    \scale
    \endpspicture
\end{document}

or:

\def\scale{%
  \psline[arrows=|-|,tbarsize=36](100,0)%
  \psline(50,-9)(50,9)%
  \foreach \x in {10,20,...,90}{\psline(\x,-3)(\x,3)}%
}

or if want it with PS code:

\def\scale{%
  \psline(100,0)
  \foreach \x in {0,10,...,100}{%
    \psline(!\x\space dup 100 mod 0 eq 
             {-18}{\x\space 50 mod 0 eq {-9}{-3} ifelse } ifelse )%   
           (!\x\space dup 100 mod 0 eq 
             {18}{\x\space 50 mod 0 eq {9}{3} ifelse} ifelse )%   
  }}

and with calculating the ccordinates only once:

\def\scale{%
  \psline(100,0)
  \multido{\ix=0+10}{11}{%
    \pscustom{%
    \code{\ix\space dup /xCoor ED 100 mod 0 eq 
        {-18}{xCoor 50 mod 0 eq {-9}{-3} ifelse } ifelse /yCoor ED}
    \moveto(!xCoor yCoor)
    \lineto(!xCoor yCoor neg)}
}}
  • sure, use (!\x\space dup 100 mod 0 eq {-18}{ dup 50 mod 0 eq {-9}{-3} ifelse } ifelse ) – user2478 Jul 18 '18 at 9:08
  • that is not so easy because PSTricks draws the line from the last point to the first one. So everything which is defined by the first point is not known to the others when changig the order of the points. – user2478 Jul 18 '18 at 11:43
  • see edited answer – user2478 Jul 18 '18 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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