FORM+CODE in Design, Art, and Architecture

Visualize: SUPERFORMULA

The superformula was first described by Johan Gielis in 2003 as a way to mathematically generate a wide variety of forms found in nature. The form generated by the equation can be controlled by setting the values of a few key parameters. The verdict is still out as to whether the superformula actually describes processes in nature or simply produces a good imitation of them.

The first step to create a basic 2-D form based on the superformula is to set the values for the parameters named m, n1, n2, and n3. The m parameter changes the number of petals on the final form, and the n parameters affect the shape and size of the petals. The equation for the superformula is based on a circle. Finding the position of each point in the final form requires iterating around the degrees of a circle, from 0 to 359, and plugging the angle and parameters into the equation.

/** * Visualize: Superformula * from Form+Code in Design, Art, and Architecture * by Casey Reas, Chandler McWilliams, and LUST * Princeton Architectural Press, 2010 * ISBN 9781568989372 * * This code was written for Processing 1.2+ * Get Processing at http://www.processing.org/download */ float scaler = 200; int m = 2; float n1 = 18; float n2 = 1; float n3 = 1; void setup() {   size(700, 700);   smooth();   noFill();   stroke(255); } void draw() {   background(0);      pushMatrix();   translate(width/2, height/2);   float newscaler = scaler;   for (int s = 16; s > 0; s--) {     beginShape();        float mm = m + s;     float nn1 = n1 + s;     float nn2 = n2 + s;     float nn3 = n3 + s;     newscaler = newscaler * 0.98;     float sscaler = newscaler;     PVector[] points = superformula(mm, nn1, nn2, nn3);     curveVertex(points[points.length-1].x * sscaler, points[points.length-1].y * sscaler);     for (int i = 0;i < points.length; i++) {       curveVertex(points[i].x * sscaler, points[i].y * sscaler);     }     curveVertex(points[0].x * sscaler, points[0].y * sscaler);     endShape();   }   popMatrix(); } PVector[] superformula(float m,float n1,float n2,float n3) {   int numPoints = 360;   float phi = TWO_PI / numPoints;   PVector[] points = new PVector[numPoints+1];   for (int i = 0;i <= numPoints;i++) {     points[i] = superformulaPoint(m,n1,n2,n3,phi * i);   }   return points; } PVector superformulaPoint(float m,float n1,float n2,float n3,float phi) {   float r;   float t1,t2;   float a=1,b=1;   float x = 0;   float y = 0;   t1 = cos(m * phi / 4) / a;   t1 = abs(t1);   t1 = pow(t1,n2);   t2 = sin(m * phi / 4) / b;   t2 = abs(t2);   t2 = pow(t2,n3);   r = pow(t1+t2,1/n1);   if (abs(r) == 0) {     x = 0;     y = 0;   }     else {     r = 1 / r;     x = r * cos(phi);     y = r * sin(phi);   }   return new PVector(x, y); }

Contributed Examples

DOWNLOAD ALL CODE EXAMPLES

We are looking for implementations of the code examples in other programming languages to post on the site. If you would like to submit a sample, or if you find a bug, please write to