TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

enter image description here

Karl is a list of randomly generated nodes by \curvepnodes using parametric points in RPN (I don't know how to use rand in algebraic expression). The number of elements of the list is \Karlnodecount + 1 or plotpoints.

In the documentation, I only see \psnline to connect the list with a straight line segment between two consecutive nodes. To close the path, I invoke \closepath inside \pscustom.

  • Unfortunately, the closing line segment does not look smooth.
  • Instead of using a straight line segment, I want to use a curved one. Using \psparametricplot[plotstyle=curve] does help a bit but the closing segment is still problematic.

enter image description here

\curvepnodes[plotpoints=40]{0}{360}{/R rand 1001 mod 1000 div 1.5 add def R t cos mul  R t sin mul}{Karl}

I also tried using \multido and \curveto but \curveto needs 3 points per invocation (two of them are control points of a bezier curve).

How to draw a closed smooth curve from a list of nodes?

share|improve this question
Does it have to be pstricks? I'm sure you can do this with tikz. – Anke Apr 9 '13 at 12:22
@Anke: The bounties are offered for a single correct answer in PSTricks. I am so sorry. Solutions in TikZ are welcome but there is no bounty for them. – kiss my armpit Apr 9 '13 at 12:25
It's ok, I'm no bounty hunter ;) If it was just about getting the desired result, I could have helped. But if this is just about proving a point or whatever, I'm not going to bother trying to help with tikz. – Anke Apr 9 '13 at 12:32
up vote 11 down vote accepted
\pstVerb{1234 srand} 
\def\PlotImage#1{% #1: no of points
  \pstVerb{ /Step 360 #1 div def } \def\randompath{}
    \xdef\randompath{\randompath(! Rand 2 mul 1 sub 2.5 add \i\space Step mul PtoC  )}}%


\PlotImage{36}  \PlotImage{142}


enter image description here

share|improve this answer
When the number of points is, say, 142, the result looks strange. – g.kov Apr 9 '13 at 17:03
@g.kov: \curvepnodes makes life easier because we don't need to calculate the angle step. – kiss my armpit Apr 9 '13 at 17:31
@g.kov: see my edit, the no of plotpoints is now no problem. – Herbert Apr 9 '13 at 17:49
@Herbert: Yes, now it's perfect. – g.kov Apr 9 '13 at 19:11
1 sub 2.5 add? – kiss my armpit Apr 9 '13 at 22:51

Sorry, I don't know PSTricks, but for comparison, this is the Metapost equivalent of Jake's TikZ solution:

enter image description here



  path p;
  p := for i = 0 step 10 until 350 : (1 randomized 1)*dir(i) .. endfor cycle;
  draw p scaled 1cm;


share|improve this answer
Ha, wow, Metapost is succinct! +1 – Jake Apr 9 '13 at 13:09
@Jake: Yes, after all, metapost follows the syntax of metafont, a language designed by Knuth: succinct, precise, and weird (in the same way as TeX is weird). – Aditya Apr 9 '13 at 13:34

\foreach \theta in {0,10,...,350} {
    \xdef\randompath{\randompath (\theta:\r) ..}
\begin{tikzpicture}[use Hobby shortcut]
\expandafter\draw\randompath cycle;
share|improve this answer
It's not PSTricks, but it's a wonderful example of how elegant PGF/TikZ can be. +1. – Sean Allred Apr 9 '13 at 12:36
There is a special bounty of 250 for your \xdef technique. I will be given at the last in your answer in another question (not this question because the fifth bounty cannot be 250). – kiss my armpit Apr 9 '13 at 13:38
That reminds me ... I must upload the latest version of hobby to CTAN. Then it becomes a smidgeon easier: \draw[use Hobby shortcut] ([closed]0:rnd+2) \foreach \ang in {0,10,...,350} { .. (\ang:rnd+2) }; – Loop Space Apr 9 '13 at 19:53
I get Use of \tikz@curveto@double doesn't match its definition.. I have a recent version of hobby. The problem seems to come from cycle – Alain Matthes Apr 17 '13 at 5:46
@AlainMatthes Didn't spot that comment. I messed around with the internals of the package and broke the cycle syntax (I think irreparably). See tex.stackexchange.com/a/121310/86 for more details. – Loop Space Jul 9 '13 at 7:59

The bullet proof solution.



\pstVerb{realtime srand}

\curvepnodes[plotpoints=\N]{0}{360}{rand 16 mod 15 div 1.5 add t PtoC}{P}
\multido{\i=0+1}{\Pnodecount}{\xdef\points{\points (P\i)}}
share|improve this answer
Use \psnccurve to save more keystrokes! – kiss my armpit Nov 12 '13 at 20:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.