[Tex/LaTex] How to draw random simple closed smooth curves but with the same perimeter

asymptotemetapostpstrickstikz-pgf

I want to draw some random simple smooth closed curves. Each smooth curve must have the same perimeter but different area.
See the following figure to illustrate what I meant clearly. Each smooth curve is assumed to have the same perimeter.

enter image description here

How to do this with PSTricks (preferred) or TikZ or Metapost or Asymptote?

The following template is provided to save your time.

\documentclass{pstricks,border=12pt,12pt}

\begin{document}
\psLoop{10}{%
\begin{pspicture}(-5,-5)(5,5)
\end{pspicture}}
\end{document}

Best Answer

Here is a solution, which uses pst-intersect's ability to save a generic path. So, first a random path is generated (how is pretty much arbitrary), then it is loaded, its path length is calculated and then it is redrawn with scaled coordinates:

\documentclass[margin=5pt, pstricks]{standalone}
\usepackage{pst-intersect}
\makeatletter
\def\SaveRandomPath{%
  \pssavepath[linestyle=none, arrows=-,ArrowInside=-]{A}{%
    \moveto(! /@S Rand 1.5 mul def @S Rand mul 1 add 0 PtoC 2 copy /@Y ED /@X ED)
    \psparametricplot[plotpoints=35]{10}{350}{@S Rand mul 1 add t Rand 0.5 sub 5 mul add PtoC}%
    \lineto(!@X @Y)
  }%
}%
\def\TraceAndScaleCurve{\pst@object{TraceAndScaleCurve}}%
\def\TraceAndScaleCurve@i#1{%
  \begin@OpenObj
    \addto@pscode{%
      \pst@intersectdict
      \PIT@name{A} -1 -1
    {\psk@plotpoints exch
      \txFunc@BezierCurve
      \ifshowpoints \txFunc@BezierShowPoints \else pop \fi
    } 4 copy
    TraceCurveOrPath PathLength #1 div 
    dup 1 exch div dup scale 5 1 roll 
    newpath TraceCurveOrPath dup scale
  }%
  \end@OpenObj
}%
\makeatother
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\multido{\i=-4+2}{5}{%
  \multido{\ii=-4+2}{5}{%
    \SaveRandomPath
    \rput(\i,\ii){\TraceAndScaleCurve{150}}}}
\end{pspicture}
\end{document}

I haven't counted the number of keystrokes, but I thought I make it clearer rather than short and cryptic ;)

enter image description here

To make it smoother, one can tweak the parameters and use e.g. plotstyle=cspline, which gives results like

enter image description here