\documentclass[12pt]{article}
\usepackage{pst-anamorphosis-add,pst-plot}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage[a4paper]{geometry}

\makeatletter
\def\psparametricplotA{\pst@object{parametricplotA}}% 	hv 2008-11-22
\def\parametricplotA{\pst@object{parametricplotA}}
\def\parametricplotA@i#1#2{\@ifnextchar[{\parametricplotA@x{#1}{#2}}{\parametricplotA@x{#1}{#2}[]}}
\def\parametricplotA@x#1#2[#3]{\@ifnextchar[{\parametricplotA@xi{#1}{#2}[#3]}{\parametricplotA@xi{#1}{#2}[#3][]}}
\def\parametricplotA@xi#1#2[#3][#4]#5{%
  \pst@killglue%
  \begingroup%
    \use@par%
    \@nameuse{beginplot@\psplotstyle}%
    \addto@pscode{%
    \tx@optionsanamorphosis
    \tx@optionsanamorphosisAdd
      #3 %prefix PS code
      \psplot@init
      /t #1 def
      /t1 #2 def
      /dt t1 t sub \psk@plotpoints div def
      /F@pstplot \ifPst@algebraic (#5)
                    \ifx\psk@PlotDerivative\@none\else
                      \psk@PlotDerivative\space { (t) tx@Derive begin Derive end } repeat
                    \fi\space
                    tx@AlgToPs begin AlgToPs end cvx
                 \else { #5 } \fi  def
      \ifPst@VarStep
         /StillZero 0 def /LastNonZeroStep dt def
         /F2@pstplot tx@Derive begin (#5) (t) Derive (t) Derive end
                     \ifx\psk@PlotDerivative\@none\else
                       \psk@PlotDerivative\space { (t) tx@Derive begin Derive end } repeat
                     \fi\space
                    tx@AlgToPs begin AlgToPs end cvx def
         %% computation of the tolerance defined by plotpoints
         /epsilon12 \ifx\psk@VarStepEpsilon\@default
                       tx@Derive begin F2@pstplot end Pyth
                       dt 3 exp abs mul
                    \else\psk@VarStepEpsilon\space 12 mul \fi def
         /ComputeStep {
           dup 1e-4 lt
           { pop StillZero 2 ge { LastNonZeroStep 2 mul } { LastNonZeroStep } ifelse /StillZero StillZero 1 add def }
           { epsilon12 exch div 1 3 div exp /StillZero 0 def }
           ifelse } bind def
      \fi
      /xy {
        \ifPst@algebraic F@pstplot \else #5 \fi
        \pst@number\psyunit mul exch
        \pst@number\psxunit mul exch
        tx@anamorphosisPathDict begin Anamorphose end
      } def
      }%
    \gdef\psplot@init{}%
    \@pstfalse
    \@nameuse{testqp@\psplotstyle}%
    \if@pst\parametricplotA@ii{#4}\else\parametricplotA@iii{#4}\fi
  \endgroup%
  \ignorespaces}
%
\def\parametricplotA@ii#1{% para is the post code
  \ifPst@VarStep%
    \addto@pscode{%
      mark xy \@nameuse{beginqp@\psplotstyle}
      { F2@pstplot Pyth ComputeStep
        t 2 copy add dup t1 gt {pop t1} if /t exch def F2@pstplot Pyth ComputeStep
        /t 3 -1 roll def 2 copy gt { exch } if pop
        /t t 3 -1 roll add dup t1 gt {pop t1} if def
        xy \@nameuse{doqp@\psplotstyle}
        t t1 eq { exit } if } loop}%
  \else\pst@killglue%
    \addto@pscode{%
      /ps@Exit false def
      xy \@nameuse{beginqp@\psplotstyle}
      \psk@plotpoints 1 sub {
        /t t dt add def
        xy \@nameuse{doqp@\psplotstyle}
        ps@Exit { exit } if
      } repeat
      ps@Exit not {
        /t t1 def
        xy \@nameuse{doqp@\psplotstyle}
      } if
    }%
  \fi%
  \addto@pscode{ #1 }%
  \@nameuse{endqp@\psplotstyle}}
%
\def\parametricplotA@iii#1{%
  \ifPst@VarStep%
    \addto@pscode{%
      /n 2 def
      mark
      { xy n 2 roll F2@pstplot Pyth
        ComputeStep t 2 copy add dup t1 gt {pop t1} if
        /t exch def F2@pstplot Pyth ComputeStep
        /t 3 -1 roll def 2 copy gt { exch } if pop
        /t t 3 -1 roll dup /LastNonZeroStep exch def add dup t1 gt {pop t1} if def /n n 2 add def
        t t1 eq { exit } if } loop
      xy n 2 roll}%
  \else\pst@killglue%
    \addto@pscode{
      mark
      /n 2 def
      \psk@plotpoints {
        xy
        n 2 roll
        /n n 2 add def
        /t t dt add def
      } repeat
      /t t1 def
      xy
      n 2 roll}%
  \fi%
  \addto@pscode{ #1 }%
  \@nameuse{endplot@\psplotstyle}}
%
%%%%%%%\psframeA ---------------------
\def\psframeA{\pst@object{psframeA}}
\def\psframeA@i(#1){%
\@ifnextchar({\psframeA@ii(#1)}{\psframeA@ii(0,0)(#1)}}
\def\psframeA@ii(#1)(#2){%
\begin@ClosedObj
\pst@getcoor{#1}\pst@tempa%
\pst@@getcoor{#2}%
\def\pst@linetype{2}%
\addto@pscode{%
    \tx@optionsanamorphosis
    \tx@optionsanamorphosisAdd
    \pst@tempa
    \pst@coor
    /Y2 ED
    /X2 ED
    /Y1 ED
    /X1 ED
    X1 Y1  tx@anamorphosisPathDict begin Anamorphose end
    moveto
    0 0.005 1.0 { %(X1,Y1)->(X2,Y1)
    /K exch def
    K X2 mul 1 K sub X1 mul add
    Y1
    tx@anamorphosisPathDict begin Anamorphose end
    lineto
    } for
    0 0.005 1.0 { % (X2,Y1)->(X2,Y2)
    /K exch def
    X2
    K Y2 mul 1 K sub Y1 mul add
    tx@anamorphosisPathDict begin Anamorphose end
    lineto
    } for
    0 0.005 1.0 { % (X2,Y2)->(X1,Y2)
    /K exch def
    K X1 mul 1 K sub X2 mul add
    Y2
    tx@anamorphosisPathDict begin Anamorphose end
    lineto
    } for
    0 0.005 1.0 { % (X1,Y2)->(X1,Y1)
    /K exch def
    X1
    K Y1 mul 1 K sub Y2 mul add
    tx@anamorphosisPathDict begin Anamorphose end
    lineto
    } for
}%
\showpointsfalse
\end@ClosedObj}
%
%%%%%%%\translateA ---------------------------
\def\translateA{\def\pst@par{}\pst@object{translateA}}
\def\translateA@i(#1){{%
\pst@@getcoor{#1}%
\addto@pscode{
    \tx@optionsanamorphosis
    \tx@optionsanamorphosisAdd
 \pst@coor
tx@anamorphosisPathDict begin Anamorphose end
    translate}}}%
%

\title{pst-anamorphosis : extensions possibles}
\author{Jürgen Gilg, Manuel Luque, Jean-Michel Sarlat}
\date{21 octobre 2011}
\begin{document}
\maketitle
\begin{abstract}
Il est relativement facile d'adapter les commandes de \textsf{PStricks} à \textsf{pst-anamorphosis}. C'est ainsi que la plupart des macros de \textsf{pst-anamorphosis-add} sont des adaptations de celles de \textsf{PStricks}. Toutes ne l'on pas été pour ne pas alourdir inutilement le package. Nous allons détailler sur un exemple la façon de procéder.

Remarque : toutes les macros ne sont pas adaptables, cela serait le cas si les anamorphoses transformaient une ligne droite en une ligne droite. Or, à part la perspective, ce n'est pas le cas. En conséquence, \verb+\psline+, \verb+\psframe+, \verb+\pspolygon+ doivent être réécrits en divisant le segment initial en un grand nombre de petits segments : pour  \verb+\pslineA+ par exemple chaque segment initial est divisé en 200 parties et ceci quelle que soit sa longueur, dans l'idéal il faudrait tenir compte de la longueur du segment avant de choisir le nombre de segmentations.
\end{abstract}
\section{\textbackslash{}psparametricplotA}
\subsection{Adaptation}
À partir d'une copie de \textbackslash{}\textsf{psparametricplot} :
\begin{enumerate}
  \item On remplace parout \textsf{psparametricplot} par \textsf{psparametricplotA} ;
  \item dans le premier \verb+\addto@pscode{%+
  \begin{verbatim}
  \addto@pscode{%
    \tx@optionsanamorphosis
    \tx@optionsanamorphosisAdd
      #3 %prefix PS code
      \psplot@init
  \end{verbatim}
  on introduit juste au début les variables de \textsf{pst-anamorphosis} ;
  \item et pour terminer dans \verb+/xy {+:
\begin{verbatim}
          /xy {
        \ifPst@algebraic F@pstplot \else #5 \fi
        \pst@number\psyunit mul exch
        \pst@number\psxunit mul exch
        tx@anamorphosisPathDict begin Anamorphose end
      } def
\end{verbatim}
 on insère à la fin les calculs propres à l'anamorphose. C'est terminé, la macro est opérationnelle !
\end{enumerate}
\subsection{Exemple}
\begin{center}
\begin{pspicture}(-6,-6)(6,6)
\pscircle[doubleline=true]{3}
\psset{type=conical}
\pscircle[linecolor=blue](0,0){1}
\pscircleA[linecolor=blue](0,0){1}
\pscircle[linecolor=blue](0,0){2}
\pscircleA[linecolor=blue](0,0){2}
\psframeA[linecolor=blue,fillstyle=solid,fillcolor=cyan](1,1)(2,2)
\psframeA[linecolor=blue,fillstyle=solid,fillcolor=cyan](-1,-1)(-2,-2)
\psframeA[linecolor=blue,fillstyle=solid,fillcolor=cyan](-1,1)(-2,2)
\psframeA[linecolor=blue,fillstyle=solid,fillcolor=cyan](1,-1)(2,-2)
\psframe[linecolor=blue,fillstyle=solid,fillcolor=cyan](1,1)(2,2)
\psframe[linecolor=blue,fillstyle=solid,fillcolor=cyan](-1,-1)(-2,-2)
\psframe[linecolor=blue,fillstyle=solid,fillcolor=cyan](-1,1)(-2,2)
\psframe[linecolor=blue,fillstyle=solid,fillcolor=cyan](1,-1)(2,-2)
\parametricplotA[plotpoints=3600,linecolor=red,linewidth=1mm]{0}{360}{%
  /Radius 1.5 0.5 t 10 mul sin mul add def
  Radius t cos mul
  Radius t sin mul
    }
\parametricplot[plotpoints=3600,linecolor=red,linewidth=1mm]{0}{360}{%
  /Radius 1.5 0.5 t 10 mul sin mul add def
  Radius t cos mul
  Radius t sin mul
    }
\multido{\n=0.5+0.5,\N=0.5+0.5}{4}{%
    \pnode(! \n\space -2){A}
    \pnode(! \n\space 2){B}
    \psline(A)(B)
    \pslineA(A)(B)
    \pnode(!-2 \N){A}
    \pnode(!2 \N){B}
    \pslineA(A)(B)
    \psline(A)(B)
    }
\multido{\n=-2.0+0.5,\N=-2.0+0.5}{4}{%
    \pnode(! \n\space -2){A}
    \pnode(! \n\space 2){B}
    \psline(A)(B)
    \pslineA(A)(B)
    \pnode(!-2 \N){A}
    \pnode(!2 \N){B}
    \pslineA(A)(B)
    \psline(A)(B)
    }
\psline(-2,0)(2,0)
\psline(0,-2)(0,2)
\pslineA(0,-2)(0,-0.5)
\pslineA(0,2)(0,0.5)
\pslineA(-2,0)(-0.5,0)
\pslineA(2,0)(0.5,0)
\psdot[dotstyle=x,dotsize=.2](0,0)
\end{pspicture}
\end{center}
\begin{verbatim}
\parametricplotA[plotpoints=3600,linecolor=red,linewidth=1mm]{0}{360}{%
  /Radius 1.5 0.5 t 10 mul sin mul add def
  Radius t cos mul
  Radius t sin mul
    }
\parametricplot[plotpoints=3600,linecolor=red,linewidth=1mm]{0}{360}{%
  /Radius 1.5 0.5 t 10 mul sin mul add def
  Radius t cos mul
  Radius t sin mul
\end{verbatim}
\section{\textbackslash{}psframeA}
\verb+\psframeA(x1,y1)(x2,y2)+ a les mêmes propriétés que \verb+\psframe+
\begin{center}
\begin{pspicture}(-6,-6)(6,6.5)
\psset{type=conical,Rmirror=3}
\psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](-0.25,-0.25)(-0.01,-0.01)
\psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](-0.25,0.25)(-0.01,0.01)
\psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](0.01,0.01)(0.25,0.25)
\psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](0.01,-0.01)(0.25,-0.25)
\multido{\ry=-2.75+1,\rY=-2.25+1}{6}{
\multido{\n=-2.75+1.00,\N=-2.25+1.00}{7}{%
    \psframeA[fillstyle=solid,fillcolor=red,linecolor=red](\n,\ry)(\N,\rY)}
    }
\multido{\ry=-3.25+1,\rY=-2.75+1}{3}{
\multido{\n=-3.25+1.00,\N=-2.75+1.00}{7}{%
    \psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](\n,\ry)(\N,\rY)}
    }
\multido{\ry=0.75+1,\rY=1.25+1}{3}{
\multido{\n=-3.25+1.00,\N=-2.75+1.00}{7}{%
    \psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](\n,\ry)(\N,\rY)}
    }
\multido{\n=-3.25+1.00,\N=-2.75+1.00}{3}{%
    \psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](\n,-0.25)(\N,0.25)}
\multido{\n=0.75+1.00,\N=1.25+1.00}{3}{%
    \psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](\n,-0.25)(\N,0.25)}
\begin{psclip}{\pscircle[fillstyle=solid,fillcolor=white,linestyle=none]{3}}
\multido{\ry=-2.75+1,\rY=-2.25+1}{6}{
\multido{\n=-2.75+1.00,\N=-2.25+1.00}{6}{%
    \psframe*[linecolor=red](\n,\ry)(\N,\rY)}
    }
\multido{\ry=-3.25+1,\rY=-2.75+1}{7}{
\multido{\n=-3.25+1.00,\N=-2.75+1.00}{7}{%
    \psframe*[linecolor=blue](\n,\ry)(\N,\rY)}
    }
\pscircle[doubleline=true]{3}
\end{psclip}
\end{pspicture}
\end{center}
\begin{verbatim}
    \multido{\ry=-2.75+1,\rY=-2.25+1}{6}{
\multido{\n=-2.75+1.00,\N=-2.25+1.00}{7}{%
    \psframeA[fillstyle=solid,fillcolor=red,linecolor=red](\n,\ry)(\N,\rY)}
    }
\multido{\ry=-3.25+1,\rY=-2.75+1}{3}{
\multido{\n=-3.25+1.00,\N=-2.75+1.00}{7}{%
    \psframeA[fillstyle=solid,fillcolor=blue,linecolor=blue](\n,\ry)(\N,\rY)}
    }
\end{verbatim}
\section{\textbackslash{}pspolygonA}
En réalité la macro \verb+pspolygonA+ n'a pas été écrite. En effet il suffit de servir de \verb+\pslineA+ et de boucler le chemin en revenant au point origine.
\begin{center}
\begin{pspicture}(-5,-5)(5,5)
\psset{type=conical,Rmirror=3}
\pspolygon[linecolor=red,linewidth=1mm](2.5;30)(2.5;90)(2.5;150)(2.5;210)(2.5;270)(2.5;330)
\pslineA[linecolor=red,linewidth=1mm](2.5;30)(2.5;90)(2.5;150)(2.5;210)(2.5;270)(2.5;330)(2.5;30)
\rput(1.25,1){\pspolygon[linecolor=blue,fillstyle=solid,linewidth=1mm,fillcolor={[rgb]{1 0.875 0.5}}](0.75;30)(0.75;90)(0.75;150)(0.75;210)(0.75;270)(0.75;330)}
\multido{\i=30+60,\I=1+1}{6}{%
    \pnode(!\i\space cos 0.75 mul 1.25 add \i\space sin 0.75 mul 1 add){A\I}
    }
\pslineA[linecolor=blue,fillstyle=solid,linewidth=1mm,fillcolor={[rgb]{1 0.875 0.5}}](A1)(A2)(A3)(A4)(A5)(A1)
\pscircle[doubleline=true]{3}
\psdot[dotstyle=x](0,0)
\end{pspicture}
\end{center}
\begin{verbatim}
\begin{pspicture}(-5,-5)(5,5)
\psset{type=conical,Rmirror=3}
\pspolygon[linecolor=red,linewidth=1mm](2.5;30)(2.5;90)(2.5;150)(2.5;210)(2.5;270)(2.5;330)
\pslineA[linecolor=red,linewidth=1mm](2.5;30)(2.5;90)(2.5;150)(2.5;210)(2.5;270)(2.5;330)(2.5;30)
\rput(1.25,1){\pspolygon[linecolor=blue,fillstyle=solid,linewidth=1mm,fillcolor={[rgb]{1 0.875 0.5}}](0.75;30)(0.75;90)(0.75;150)(0.75;210)(0.75;270)(0.75;330)}
\multido{\i=30+60,\I=1+1}{6}{%
    \pnode(!\i\space cos 0.75 mul 1.25 add \i\space sin 0.75 mul 1 add){A\I}
    }
\pslineA[linecolor=blue,fillstyle=solid,linewidth=1mm,fillcolor={[rgb]{1 0.875 0.5}}](A1)(A2)(A3)(A4)(A5)(A1)
\pscircle[doubleline=true]{3}
\psdot[dotstyle=x](0,0)
\end{pspicture}
\end{verbatim}
On remarquera que le \verb+\rput(1.25,1)+ doit être remplacé par un calcul adapté. La macro \verb+\rputA+ n'a pas été définie.
\end{document} 