[pstricks] Make vary the thickness of a line

Denis Girou Denis.Girou at idris.fr
Tue Jun 24 22:00:37 CEST 2003


>>>>> "Manuel.Luque" == MLuque  <MLuque5130 at aol.com> writes:

    Manuel.Luque> Would be it possible, on PSTricks, to implant a command of the type:
    Manuel.Luque> \pscurve[linewidthbegin=5mm,linewidthend=0.1mm] (x0,y0) (...) (xn,yn)

    Manuel.Luque> Allowing to make vary the thickness of the line of the beginning at the end ?

  I am rather convainced that you cannot have a general solution with smooth
lines continuously decreasing. The lineto, arcto and curveto PostScript
operators work with a fixed value of the line width. For very simple straight
lines, you can erase conveniently the unwanted parts of the lines (see last
example), but not in the general case.

  Nevertheless, what is possible is to automatically increase or decrease the
line width for each segment drawn. If there are more than few ones and if the
variation is not too important, this can produce acceptable results. You can
also improve the result with the "linecap" PostScript operator (see examples).

  If this is for your poulp (!), take care that some things are broken with
this modified version of \pscurve, specially the "doubleline" option, but you
can emulate it behavior using two curves.

\documentclass[a4paper]{article}

\usepackage{pstricks}

\setlength{\textheight}{26cm}

\pagestyle{empty}

\makeatletter

\def\psset at LineWidthStep#1{\pst at getlength{#1}{\PstLineWidthStep}}
\psset at LineWidthStep{0}% Default value

\def\psset at LineCap#1{\pst at getint{#1}{\PstLineCap}}
\psset at LineCap{0}% Default value

\def\pscurve at i{%
\pst at getarrows{%
\begin at OpenObj
% D.G. modification begin - Jun. 24, 2003
\addto at pscode{/LineWidth \pst at number\pslinewidth def}%
% D.G. modification end
\pst at getcoors[\pscurve at ii}}

\pst at def{OpenCurve}<{%
% D.G. modification begin - Jun. 24, 2003
/NC{stroke
    x y moveto
    CC x1 y1 x2 y2 x y curveto
    /LineWidth LineWidth \PstLineWidthStep add def
    LineWidth setlinewidth
    \PstLineCap setlinecap} def
/EOC{x dx sub y dy sub 4 2 roll
     ArrowB
     2 copy
     stroke
     x y moveto
     curveto
     /LineWidth LineWidth \PstLineWidthStep add def
     LineWidth setlinewidth
     \PstLineCap setlinecap
     stroke} def
% D.G. modification end
NArray
n 3 lt { n { pop pop } repeat }
       { BOC
         /n n 3 sub def
         n { NC } repeat
         EOC } ifelse}>

\makeatother

\begin{document}

\psset{subgriddiv=0}

\begin{pspicture}(10,4)\psgrid
  \pscurve(0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[LineWidthStep=0.05](0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[linewidth=0.2,LineWidthStep=0.05](0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[linewidth=0.2,LineWidthStep=0.05,LineCap=2]
          (0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[linewidth=0.2,LineWidthStep=0.05,LineCap=1]
          (0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[linewidth=1,LineWidthStep=-0.5](0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \pscurve[linewidth=1,LineWidthStep=-0.1,LineCap=1]
          (0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,4)\psgrid
  \psset{LineCap=1}%
  \pscurve[linewidth=0.06,LineWidthStep=0.06]
          (0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
  \pscurve[linewidth=0.03,LineWidthStep=0.03,linecolor=green]
          (0,0)(3,3)(5,1)(6,4)(8,2)(10,2)
\end{pspicture}

\vspace{1cm}
\begin{pspicture}(10,5)\psgrid
  \psline[linewidth=0.5](1,1)(9,1)(9,5)
  \pspolygon*[linecolor=white](1,1.25)(9.083,0.917)(9.25,5)
                              (8.75,5)(8.75,1.25)
\end{pspicture}

\end{document}


D.G.



More information about the PSTricks mailing list