Design Computation

## 3D Geometry

Most of Processing’s drawing functions have a 3-dimensional equivalent.

Functions like line() are called “overloaded” because there are two sets of parameters you could possibly pass to it. Processing knows only by the number and type of values you pass it whether to select the 2D or 3D version.
RENDERING MODE

size() does more than determine the size of the sketch. It also determines whether you’re drawing 2-dimensionally or 3-dimensionally.

Default Java2D renderer.

size( 700, 400 );
size( 700, 400, JAVA2D );

Processing’s 2D renderer.

size( 700, 400, P2D );

Processing’s 3D renderer. Enables 3D support.

size( 700, 400, P3D );

Processing’s OpenGL renderer. This requires importing the OpenGL library.

size( 700, 400, OPENGL );

## Some Three-Dimensional Graphics

Getting started in 3D is just a matter of looking at the Processing API for functions that include z values.

Just specify more coordinates for the 3D versions of each function.

line( x1, y1, z1, x2, y2, z2 );
vertex( x1, y1, z1 );

### Coordinates

In the default coordinate system, negative z-values go away from you, and positive ones go toward you.

### Form and Shape

From this point on, the challenge becomes how to represent form through computational means, through the mathematical and logical relationships that can be established by code.

Lines and depth.

``````
void setup(){
size(700, 400, P3D);
stroke(0, 100);
}

void draw(){
background(255);
for( int x=0; x<=width; x+=50 ){
for( int y=0; y<=height; y+=50 ){
line(x, y, 0, x, y, mouseY-height/2);
}
}
}
``````

Generic spiral.

``````
void setup(){
size(700, 400, P3D);
noFill();
}

void draw(){
background(255);
beginShape();
for( float r = 0; r < TWO_PI*20; r += 0.1 ){
vertex( 200*cos(r), 200*sin(r), -r*10 );
}
endShape();
}

``````