如何使用嵌套的 ifelse 运算符重写下面的循环?

如何使用嵌套的 ifelse 运算符重写下面的循环?

ifelse您能用嵌套的 PostScript运算符重写循环部分吗?

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

在此处输入图片描述

答案1

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

或者:

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

或者如果需要 PS 代码:

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

并且仅计算一次坐标:

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

相关内容