/** A pumpkin for the toxiclibs Meshbuilder by guru */ import toxi.math.waves.*; import toxi.geom.*; import toxi.geom.mesh.*; TriangleMesh mesh = new TriangleMesh(); void setup() { size(300, 300, P3D); SurfaceFunction sf = new SphereDings(); SurfaceMeshBuilder b = new SurfaceMeshBuilder(sf); mesh = (TriangleMesh)b.createMesh(null, 80, 80); } void draw() { background(255); lights(); translate(width/2, height/2, 0); rotateY( frameCount/25.0 ); rotateX(-0.4); specular(2.0); fill(230,120,0); noStroke(); SurfaceFunction sf = new SphereDings(); SurfaceMeshBuilder b = new SurfaceMeshBuilder(sf); mesh = (TriangleMesh)b.createMesh(null, 80, 80); beginShape(TRIANGLES); for (Iterator i=mesh.faces.iterator(); i.hasNext();) { Face f=(Face)i.next(); vertex(f.a); vertex(f.b); vertex(f.c); } endShape(); } void vertex(Vec3D v) { vertex(v.x, v.y, v.z); } class SphereDings implements SurfaceFunction { public Vec3D computeVertexFor( Vec3D p, float phi, float theta ) { phi -= HALF_PI; float cosPhi = cos(phi); float cosTheta = cos(theta); float sinPhi = sin(phi); float sinTheta = sin(theta); float t = cosPhi; p.x = t * cosTheta; p.y = sinPhi; p.z = t * sinTheta; float r = sin( (phi -PI/2)/2 ) - abs(0.03 * sin( theta * 5 )) ; return p.scaleSelf( r ); } public float getPhiRange() { return PI; } public int getPhiResolutionLimit( int res ) { return res; } public float getThetaRange() { return TWO_PI; } public int getThetaResolutionLimit( int res ) { return res; } }