2

A part of my code (especially iterating a list of colors with 2 additional counters) below does not seem straightforward.

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

enter image description here

How to iterate a list of colors with two additional counters more elegantly?

0
4
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}

enter image description here

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.