[pstricks] colored lines

Herbert Voss Herbert.Voss at fu-berlin.de
Thu Dec 23 14:10:29 CET 2021



Am 23.12.21 um 13:46 schrieb Hensh, Richard:
> The code below throws 8 errors. Here's the first:
>
>     ! Undefined control sequence.
>     <argument>  10 dict begin [ \psgetColorValues
>                                                   {\ps at startColor } ]
>     dup == alo..
>

Sorry should be

\psgetRGBColorValues


the RGB  was missing

Herbert

>
> I have the latest MikTeX installation. I'm a bit stumped.
>
> regards
> rick
>
>
> ------------------------------------------------------------------------
> *From:* PSTricks <pstricks-bounces+hensh=math.msu.edu at tug.org> on 
> behalf of Herbert Voss <Herbert.Voss at fu-berlin.de>
> *Sent:* Thursday, December 23, 2021 6:43 AM
> *To:* Graphics with PSTricks <pstricks at tug.org>
> *Subject:* [pstricks] colored lines
> Hello all,
>
> merry christmas to all of you
>
> \documentclass{article}
> \usepackage{pstricks-add}
> \makeatletter
> \define at key[psset]{pstricks}{startColor}[black]{%
>    \colorlet{tempcolor}[rgb]{#1}%   we need rgb
>    \pst at getcolor{tempcolor}\ps at startColor}
> \define at key[psset]{pstricks}{endColor}[white]{%
>    \colorlet{tempcolor}[rgb]{#1}%
>    \pst at getcolor{tempcolor}\ps at endColor}
> \psset[pstricks]{startColor=black,endColor=white}
>
> \def\pscolorLine{\def\pst at par{}\pst at object{pscolorLine}}
> \def\pscolorLine at i{%
>    \pst at getarrows{%
>      \begin at OpenObj
>      \pscolorLine at ii}}
>
> \def\pscolorLine at ii(#1){\@ifnextchar({\pscolorLine at iii(#1)}{\pscolorLine at iii(0,0)(#1)}}%
>
> \def\pscolorLine at iii(#1,#2)(#3,#4){%
>    \use at par
> \ifx\psk at arrowA\@empty\else\psline[linecolor=\ps at startColor]{->}(!#3 0.5
> mul #4 0.5 mul)(#1,#2)\fi
> \ifx\psk at arrowB\@empty\else\psline[linecolor=\ps at endColor]{->}(!#1 0.5
> mul #2 0.5 mul)(#3,#4)\fi
>    \pst at getcoor{#1,#2}\pst at tempA
>    \pst at getcoor{#3,#4}\pst at tempB
>    \addto at pscode{
>      10 dict begin
>      [ \psgetColorValues{\ps at startColor} ] dup == aload length 1 eq {
> dup dup } if
>        3 copy 3 array astore /startColor ED
>      [ \psgetColorValues{\ps at endColor} ] dup == aload length 1 eq { dup
> dup } if
>        3 copy 3 array astore /endColor ED
> %   on stack R1 G1 B1 R2 G2 B2
>      4 -1 roll               % R1 G1 R2 G2 B2 B1
>      sub 256 div /dB ED      % R1 G1 R2 G2
>      3 -1 roll               % R1 R2 G2 G1
>      sub 256 div /dG ED      % R1 R2
>      exch sub 256 div /dR ED
>      \pst at tempB /Y2 ED /X2 ED
>      \pst at tempA /Y1 ED /X1 ED
>      Y2 Y1 sub X2 X1 sub atan /Angle ED
>      Y2 Y1 sub Angle sin dup 0 eq { pop }{ div } ifelse /L_line ED     %
> line length
>      \ifx\psk at arrowA\@empty\else
>        X2 X1 sub L_line div \psk at arrowlength\space mul
> \pst at number\psxunit mul X1 add /X1 ED
>        Y2 Y1 sub L_line div \psk at arrowlength\space mul
> \pst at number\psyunit mul Y1 add /Y1 ED
>       \fi
>      \ifx\psk at arrowB\@empty\else
>        X2 X1 sub L_line div \psk at arrowlength\space mul
> \pst at number\psxunit mul X2 exch sub /X2 ED
>        Y2 Y1 sub L_line div \psk at arrowlength\space mul
> \pst at number\psyunit mul Y2 exch sub /Y2 ED
>       \fi
>      Y2 Y1 sub 256 div /dY ED
>      X2 X1 sub 256 div /dX ED
> %    dR dG dB == == ==
> %startColor == endColor ==
>      \ifPst at noCurrentPoint\else\pst at cp\fi       % current point?
>      0 1 255 {
>        /dIndex ED
> %startColor ==
>        X1 Y1 moveto
>        X1 dX add  Y1 dY add % start for coordinate array
>        gsave
>        lineto
>        CP /Y1 ED /X1 ED
>        \pst at number\pslinewidth SLW
>        startColor aload pop 3 copy setrgbcolor
>        % on stack r g b
>        dB add 3 1 roll    % b+dB r g
>        dG add 3 1 roll    % b+dB g+dG r
>        dR add 3 1 roll    % b+dB g+dG r+dR
>        3 array astore /startColor ED
>        stroke
>        grestore
>      } for
>      end
>    }%
>    \end at OpenObj
>    \ignorespaces
> }
>
> \makeatother
>
> \begin{document}
>
> \begin{pspicture}[linewidth=12pt,showgrid](-5,-5)(5,5)
> \pscolorLine(0,-5)(0,5)
> \pscolorLine[startColor=cyan,endColor=magenta](-5,0)(5,0)
> \pscolorLine[startColor=blue,endColor=green]{->}(-5,5)(5,-5)
> \pscolorLine[startColor=red,endColor=blue]{<->}(-5,-5)(5,5)
> \end{pspicture}
>
> \end{document}
>
>
> --
> list: https://lists.tug.org/pstricks
> archive: https://tug.org/pipermail/pstricks/



More information about the PSTricks mailing list.