import com.processinghacks.triangulate.*; import com.processinghacks.arcball.*; Vector points = new Vector(); Vector triangles = new Vector(); ArcBall arcball; PImage img; boolean drawHeight = true; void setup() { size(400,400,P3D); // attach an arcball so we can quickly inspect the scene arcball = new ArcBall(width/2,height/2,0,height/2,this); // build a 1D texture (hue gradient) // 256 pixels across, from hue 0->255 in 25 pixel bands img = new PImage(256,1); int bandSize = 25; colorMode(HSB); for (int i = 0; i < img.width; i++) { img.set(i,0,color(255-i+(i%bandSize),255,255)); } // make a 2D grid of points int gridw = width/20; int gridh = height/20; for (int i = 0; i <= gridw; i++) { for (int j = 0; j <= gridh; j++) { float x = i*width/gridw; float y = j*height/gridh; points.add(new Point3f(x,y,0.0)); } } // triangulate points triangles = Triangulate.triangulate(points); // modify height of points by noise field float t = millis()/1000.0; for (int i = 0; i < points.size(); i++) { Point3f p = (Point3f)points.get(i); p.z = noise(3*p.x/width,3*p.y/height,0.0)*255; } } void draw() { background(255); translate(width/2,height/2); scale(0.66); translate(-width/2,-height/2); // draw triangle mesh noStroke(); fill(255); beginShape(TRIANGLES); textureMode(IMAGE); texture(img); for (int i = 0; i < triangles.size(); i++) { Triangle t = (Triangle)triangles.get(i); if (drawHeight) { vertex(t.p1.x,t.p1.y,t.p1.z,t.p1.z,0.0); vertex(t.p2.x,t.p2.y,t.p2.z,t.p2.z,0.0); vertex(t.p3.x,t.p3.y,t.p3.z,t.p3.z,0.0); } else { vertex(t.p1.x,t.p1.y,0.0,t.p1.z,0.0); vertex(t.p2.x,t.p2.y,0.0,t.p2.z,0.0); vertex(t.p3.x,t.p3.y,0.0,t.p3.z,0.0); } } endShape(); // modify height by noise field according to elapsed time float t = millis()/1000.0; for (int i = 0; i < points.size(); i++) { Point3f p = (Point3f)points.get(i); p.z = noise(3*p.x/width,3*p.y/height,t)*255; } } // hit any key to toggle drawing the height of the points void keyReleased() { drawHeight = !drawHeight; }