/** CurveLathe.pde http://www.davebollinger.com The technique intended to be illustrated here is how to use Processing's transforms along with modelXYZ to get around having to know much about the math going on underneath. drag to rotate right-click to generate next shape */ //import processing.opengl.*; // simple storage class for a 3d point class P3 { float x, y, z; P3() { this(0,0,0); } P3(float _x, float _y, float _z) { x=_x; y=_y; z=_z; } void draw() { vertex(x,y,z); } } // how many points "around" the mesh int usteps = 8; // how many points "along" the mesh int vsteps = 50; // the u-shape points to be lathed along a curve // ("+1" for convenience to dup first point and close the curve) P3 [] shape = new P3[usteps+1]; // these values will determine an L-system type iterated curve: float drotx, droty, drotz, dtran; // the resulting mesh by lathing "shape" along the curve P3 [][] mesh = new P3[vsteps][usteps+1]; // camera rotation float rotx, roty; void setup() { size(500,500,P3D); //size(500,500,OPENGL); build(); } void build() { // // define the u-shape on a specific plane // x-z plane is used here, then lathed along y // but you could use other combinations. // this makes regular polygons (approximating circles) // but you could use any topologically valid shape: // float r = 5f; for (int u=0; u<=usteps; u++) { float theta = float(u) / float(usteps) * TWO_PI; shape[u] = new P3(r*cos(theta), 0, r*sin(theta)); } // // now define the "curve", here we're using an L-system, // for a standard "straight along the axis" lathe, use: // drotx = droty = drotz = 0f; // otherwise... // drotx = random(-0.3,0.3); droty = random(-0.3,0.3); drotz = random(-0.3,0.3); dtran = random(5,10); // // now iterate the L-system and build the mesh along the curve // camera(); // to reset transforms for (int v=0; v