# Supershapes / Superformula

Actionscript:
1. // Superformula (equations from):
3. // http://en.wikipedia.org/wiki/Superformula
4. const TWO_PI:Number = Math.PI * 2;
5. function superShape(a:Number, b:Number, m:Number, n1:Number, n2:Number, n3:Number, pnt:Point, scale:Number):void{
6.     var r:Number = 0
7.     var p:Number = 0;
8.     var xp:Number = 0, yp:Number = 0;
9.     while(p <= TWO_PI){
10.         var ang:Number = m * p / 4;
11.         with(Math){
12.             r = pow(pow(abs(cos(ang) / a), n2) + pow(abs(sin(ang) / b), n3),-1/n1);
13.             xp = r * cos(p);
14.             yp = r * sin(p);
15.         }
16.         p += .01;
17.         canvas.setPixel(pnt.x + xp *scale, pnt.y + yp * scale,  0xFFFFFF);
18.      }
19. }
20. // test it out:
21. var canvas:BitmapData = new BitmapData(700,600,false, 0x000000);
23.
24. superShape(1, 1, 5, 23, 23, 23, new Point(100,80), 30);
25. superShape(1, 1, 5, 13, 13, 3, new Point(200,80), 30);
26. superShape(1, 1, 8, 3, 13, 3, new Point(300,80), 30);
27. superShape(10,8, 16, 30, 13, 3, new Point(450,80), 30);
28. superShape(1,1, 1, .5, .5, .5, new Point(100,190), 100);
29.
30. for (var i:int = 0; i <150; i++){
31.   superShape(1,1, 2, 1+i/800, 4, 8-i * .1, new Point(550,350), 50);
32. }
33. for (i = 0; i <20; i++){
34.   superShape(1.1,1.2, 6, 2 + i , 4, 9 - i, new Point(200,350), 50);
35. }

The above snippet demos a function that will draw Supershapes using the Superformula...

From wikipedia:
The Superformula appeared in a work by Johan Gielis. It was obtained by generalizing the superellipse, named and popularized by Piet Hein...

Here is the result of the above code:

You can read more about the Superformula here in the original paper by Gielis.

wikipedia entry...

3d Supershapes by Paul Bourke