[pstricks] Re : Lines (curves) with gradient color...
Werner Grundlingh
wgrundlingh at gmail.com
Tue Jul 10 07:31:11 CEST 2007
Dear Herbert,
The code below was sent by Manuel Luque roughly 2 months ago in reply
to a question I had with colouring a line (or curve) with a gradient.
Reading through the Postscript code I notice that the final line is
made up of short 'strokes' of line segments, each a colour increment
apart. This naive approach works, but clearly shows around (sharp)
curve bends. Is there a better way to do this using postscript so that
the resulting curve is smooth with colour changes? ...almost like
plotting (say) 'plotpoints' of the actual curve that is clipped, each
a colour increment apart?
Would this be a property that may be added in future
releases/revisions to pst-slpe or pst-grad? The ideal, of course,
would be to specify the options for a line (or parametric curve) using
a similar notation as suggested by pst-slpe
fillstyle=slopes,slopecolors=0 1 1 1 1 0 0 0 2 1 1 1 3
for example.
Werner
On 5/8/07, mluque5130 at aol.com <mluque5130 at aol.com> wrote:
>
> Here a test, of 2003, but which answers, I think, with your question.
> With you to adapt it, possibly...
>
> \documentclass[a4paper]{article}
>
> \usepackage[height=25cm,width=17cm]{geometry}
> \usepackage[latin1]{inputenc}
> \usepackage{pstricks,pst-xkey,pst-plot}
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> % Essai de Manuel Luque 19 février 2003
> % transformé par Denis Girou le 25 février 2003
> % révisé le 9 mai 2007
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \makeatletter
>
> \pst at addfams{pst-HSB}
>
> \define at key[psset]{pst-HSB}{HueBegin}{% Between 0 and 1
> \edef\PstParametricplotHSB at HueBegin{#1}}
>
> \define at key[psset]{pst-HSB}{HueEnd}{% Between 0 and 1
> \edef\PstParametricplotHSB at HueEnd{#1}}
>
> \newif\ifPst at HSB
> \define at key[psset]{pst-HSB}{HSB}[true]{\@nameuse{Pst at HSB#1}}
>
> % Default values
> \psset[pst-HSB]{HueBegin=0,HueEnd=1,HSB=true}
>
> \def\parametricplotHSB{\pst at object{parametricplotHSB}}
> \def\parametricplotHSB at i{\@ifnextchar[{\parametricplotHSB at do}{\parametricplotHSB at do[]}}
> \def\parametricplotHSB at do[#1]#2#3#4{{%
> \psset{#1}%
> \begin at ClosedObj
> \addto at pscode{%
> /t #2 def
> /dt #3 t sub \psk at plotpoints\space div def
> /t t dt sub def
> /Counter 0 def
> \psk at plotpoints {
> /t t dt add def
> /Counter Counter 1 add def
> #4
> \pst at number\psyunit mul exch
> \pst at number\psxunit mul exch
> 1 Counter eq
> {moveto} % First point
> {\ifPst at HSB % Other points than the first one
> /PointY exch def
> /PointX exch def
> Counter \psk at plotpoints\space div
> \PstParametricplotHSB at HueEnd\space
> \PstParametricplotHSB at HueBegin\space sub mul
> \PstParametricplotHSB at HueBegin\space add
> 1 1 sethsbcolor
> PointX PointY lineto
> stroke
> PointX PointY moveto
> \else
> lineto
> \fi} ifelse
> } repeat}% fin du code ps
> \end at ClosedObj}} % fin de la commande PSTricks
>
> \makeatother
>
> % La façon de procéder a été copiée sur pst-plot
>
> \title{Vos courbes aux couleurs de l'arc-en-ciel !}
> \author{Denis GIROU, Manuel LUQUE}
> \date{19-25 février 2003, révisé le 9 mai 2007}
>
> \begin{document}
>
> \maketitle
>
> Cette commande \verb+\parametricplotHSB+, est dérivée de
> \verb+\parametricplot+ du package \texttt{pst-plot} de Timothy Van Zand.
> Elle en reprend l'essentiel.
>
> Elle s'emploie comme celle de \verb+\parametricplot+, mais ne
> supporte pas les options de style \verb+linestyle+. Par défaut le codage
> \texttt{HSB=true} est activé, on alors une courbe qui déploie toutes les
> couleurs de l'arc-en-ciel sur sa longueur.
>
> Une nouvelle option : on peut choisir la couleur de début et la
> couleur de la fin de la courbe avec les paramètres :
> \verb+HueBegin=0,HueEnd=0.5+, par exemple ; les valeurs de
> \texttt{H} étant choisies entre 0 et 1.
>
> Avec l'option \texttt{HSB=false}, les options de couleurs classiques
> redeviennent opérantes.
>
> Le nombre de points se fixe avec le paramètre : \texttt{plotpoints=1000}
>
> \begin{verbatim}
> \begin{pspicture}(0,-4.5)(10,4.5)
> \psgrid(0,-4)(10,4)
> \psset{plotpoints=300}
>
> \parametricplotHSB[linewidth=1mm,HSB=false,linecolor=red]{0}{360}
> {t t 36 div t sin 4 mul}
> \parametricplotHSB[linewidth=1mm]{0}{360}{t t 36 div t
> cos 4 mul}
> \end{pspicture}
> \end{verbatim}
>
> \begin{center}
> \begin{pspicture}(0,-5)(10,5)
> \psgrid(0,-4)(10,4)
> \psset{plotpoints=300}%
>
> \parametricplotHSB[linewidth=1mm,HSB=false,linecolor=red]{0}{360}
> {t t 36 div t sin 4 mul}
> \parametricplotHSB[linewidth=1mm]{0}{360}{t t 36 div t
> cos 4 mul}
> \end{pspicture}
> \end{center}
>
> \begin{center}
> \begin{pspicture}(0,-5)(10,5)
> \psgrid(0,-4)(10,4)
> \psset{plotpoints=300}%
>
> \parametricplotHSB[linewidth=1mm,HueBegin=0,HueEnd=0.5]{0}{360}
> {t t 36 div t sin 4 mul}
>
> \parametricplotHSB[linewidth=1mm,HueBegin=0.5,HueEnd=0.7]{0}{360}
> {t t 36 div t cos 4 mul}
>
> \parametricplotHSB[linewidth=1mm,HueBegin=0.8,HueEnd=1]{0}{360}
> {t t 36 div t sin 2 mul}
> \end{pspicture}
> \end{center}
>
> \begin{center}
> \begin{pspicture}(-5,-5)(5,5)
> \psframe*[linecolor=lightgray](-5,-4)(5,4)
> \psgrid[gridlabels=0,subgriddiv=0](-5,-4)(5,4)
> \multido{\nxDiv=-5+0.2}{50}{%
> \psline(\nxDiv,-.1)(\nxDiv,0.1)}
> \multido{\nyDiv=-4.0+0.2}{40}{%
> \psline(-0.1,\nyDiv)(0.1,\nyDiv)}
> \psset{linewidth=1mm}%
>
> \parametricplotHSB[plotpoints=1000,linecolor=blue,HSB=false,yunit=0.5]{-5}{5}{%
> t
> /temps t 2e-3 mul def
> /frequence2 100 def
> frequence2 360 mul temps mul cos
> 1 mul 3 add
> }
> \parametricplotHSB[plotpoints=10000,yunit=1]{-5}{5}{%
> t
> /temps t 2e-3 mul def
> /frequence1 1200 def
> /frequence2 100 def
> frequence2 360 mul temps mul cos
> 1 mul 3 add
> frequence1 360 mul temps mul cos
> 4 mul
> mul
> 0.1 mul
> }
> \end{pspicture}
> \end{center}
>
> \end{document}
>
> ML 2007
More information about the PSTricks
mailing list