如何更优雅地用两个附加计数器来迭代颜色列表?

如何更优雅地用两个附加计数器来迭代颜色列表?

下面我的部分代码(特别是用 2 个附加计数器迭代颜色列表)看起来并不简单。

\documentclass[pstricks,border=12pt,dvipsnames]{standalone}
\usepackage{pst-node,pst-plot}
\def\R[#1,#2]{(1+3*(#2+1)/#1)}
\pstVerb{/I2P {AlgParser cvx exec} def}

\usepackage{etoolbox}
\def\mycolors{}
\begingroup
\renewcommand\DefineNamedColor[4]{\listgadd{\mycolors}{#2}}
\input{dvipsnam.def}
\endgroup

\newcounter{ia}
\newcounter{ib}
\setcounter{ia}{0}
\setcounter{ib}{1}

\def\object#1{%
    \pscustom[fillstyle=solid,fillcolor=#1]{\psarc(0,0){!\R[\N,\theia] I2P}{(A\theia)}{(A\theib)}\psarcn(0,0){1}{(A\theib)}{(A\theia)}\closepath}%
    \stepcounter{ia}\stepcounter{ib}%
}


\begin{document}
\def\do#1{\object{#1}}
\makeatletter
\def\N{68}
\begin{pspicture}(-2.5,-3.5)(4,2)
    \degrees[\N]
    \curvepnodes[plotpoints=\numexpr\N+1]{0}{\N}{\R[\N,t] I2P t \pst@angleunit PtoC}{A}
    \dolistloop{\mycolors}
\end{pspicture}
\makeatother
\end{document}

在此处输入图片描述

如何更优雅地用两个附加计数器来迭代颜色列表?

答案1

A solution for all named colors:

\documentclass[pstricks,border=12pt,dvipsnames]{standalone}
\usepackage{pst-node,pst-plot}
\def\R[#1,#2]{(1+3*(#2+1)/#1) AlgParser cvx exec }

\newcounter{Color}    \setcounter{Color}{0}
\def\object#1#2#3{%
  \pscustom[fillstyle=solid,fillcolor=#1,linewidth=0.1pt]{%
    \psarc(0,0){!\R[#3,#1] }{(A#1)}{(A#2)}
    \psarcn(0,0){1}{(A#2)}{(A#1)}\closepath}}
\makeatletter
\def\showColors#1#2{%
  \begin{pspicture}(-2.5,-3.5)(4,2)
    \rput[lb](1.2,0.1){\texttt{#2}}
    \degrees[#1]
    \curvepnodes[plotpoints=\numexpr#1+1]{0}{#1}{\R[#1,t] t \pst@angleunit PtoC}{A}
    \multido{\iA=0+1,\iB=1+1}{#1}{\object{\iA}{\iB}{#1}}
  \end{pspicture}}
\makeatother

\begin{document}
\def\DefineNamedColor#1#2#3#4{\definecolor{\theColor}{#3}{#4}\stepcounter{Color}}
\input{dvipsnam.def}
\expandafter\showColors\expandafter{\the\numexpr\theColor}{dvipsnames}
%
\setcounter{Color}{0}
\def\preparecolorset#1#2#3#4{\expandafter\getcolors#4;;\@nil}
\def\getcolors#1,#2,#3,#4;#5;#6\@nil{%
  \definecolor{\theColor}{rgb}{#2,#3,#4}%
  \stepcounter{Color}%
  \ifx\relax#5\relax\else\getcolors#5;#6\@nil\fi}
\input{x11nam.def}
\expandafter\showColors\expandafter{\the\numexpr\theColor}{x11names}
%
\setcounter{Color}{0}
\input{svgnam.def}
\expandafter\showColors\expandafter{\the\numexpr\theColor}{svgnames}

\end{document}

在此处输入图片描述

相关内容