The Danish writer and inventer Piet Hein was consulted during the construction of Stockholm's Sergel's Torg for help in designing the central oval pool. The architects had a problem with its design: an ellipse was too pointy, a rectangle blocked too much traffic, and a patchwork of eight arcs looked ugly and wouldn't nest nicely.

Piet Hein looked at the curves defined here, which he called superellipses and decided that the curve where n = 2.5 was the one that had the best blend of elliptical and rectangular beauty.

Two other curious facts about this equation. First, there's no reason to limit n >= 1 (the code here explicitly forbids it). When n = 2/3 the shape is an astroid. Second, if n = 3 and you remove the absolute value signs in the formula then you get the Witch of Agnesi curve.

KPV I did some testing and found that this construct works for tcl 8.0, 8.3.2 and 8.4.2 but not for 8.4.4. Why did you use the empty name for your global array instead of a real name like, say, "G"? It strikes me as kind of a hacky trick exploiting a corner of the language; this often leads to incompatibilities and to code confusing to newcomers.

Also, I had to change format %02x to format %04x because it was producing illegal colors like #ffffd7d700.

DKF: Is there a good reason for such hackery? (The colour issue is simply due to the fact that the core X colour model is 48-bit RGB.) (KPV see below)

ulis I find the name (x) very informative that x is special in some way (here, it's a global parameter). And I love this notation. I can't see any incompatibility or confusion with this. But, I agree with you, it can be hard to understand for a newcomer (and this code is not for a newcomer).

If the empty name is not supported in some version of Tcl, it's a bug that can be reported.

If you find some illegal color, this demonstrates that there is a bug in my code and I'm searching for it (but maybe it's a 64 bits bug).

I hacked this code to share the beauty of mathematics (and the efficiency of Tcl). Feel free to add your own version that will fullfil your aesthetic needs.

KPV: my bad with the color--I missed one line, which normalizes the colors, when I was converting from $(g) format to $G(g) to make it work under 8.4.4. Don't get me wrong, I think this is fun little program with a very nice visual look.

KPV: figured out the problem with the empty name array. It turns out that tkcon sets {} to the result of the last command. So when I pasted the code into the tkcon's console window I got all the errors you see above. I've emailed JH about this.

aa changed the proc, for, and foreach style in order to repair the line-continuation problems that were introduced by a recent spammish vandalization of the page.