Skip to content

Instantly share code, notes, and snippets.

@corbanbrook
Created January 4, 2010 20:35
Show Gist options
  • Save corbanbrook/268836 to your computer and use it in GitHub Desktop.
Save corbanbrook/268836 to your computer and use it in GitHub Desktop.
ArrayList peaks;
void setup() {
size(400, 200, P3D);
peaks = new ArrayList();
for ( int z = 0; z < 48; z++ ) {
int[] p = new int[48];
for ( int x = 0; x < p.length; x++ ) {
p[x] = (int)random(-50);
}
peaks.add(p);
}
}
float moveX;
void draw() {
noFill();
background(200);
ambientLight(50, 0, 0);
directionalLight(255, 255, 255, width/2, height/2, 0);
moveX += sin(frameCount/100.0);
camera(width/2 + moveX, height/2, 200, width/2, height/2, 0, 0, 1, 0);
int stripWidth = 20;
int stripLength = 20;
fill(255);
//noStroke();
pushMatrix();
translate(-width/2,200,-100);
for ( int z = 0; z < peaks.size()-1; z++ ) {
int[] p1 = (int[]) peaks.get(z);
int[] p2 = (int[]) peaks.get(z+1);
beginShape(TRIANGLES);
for ( int x = 0; x < p1.length -1; x++ ) {
vertex(x * stripLength, p1[x], z * -stripWidth);
vertex((x+1) * stripLength, p1[x+1], z * -stripWidth);
vertex((x) * stripLength, p2[x], (z+1) * -stripWidth );
vertex((x) * stripLength, p2[x], (z+1) * -stripWidth);
vertex((x+1) * stripLength, p2[x+1], (z+1) * -stripWidth);
vertex((x+1) * stripLength, p1[x+1], z * -stripWidth);
}
endShape();
}
popMatrix();
if ( frameCount % 10 == 0 ) {
int[] p = (int[]) peaks.get(0); // save front strip
peaks.remove(0); // delete front strip
peaks.add(p); // put deleted strip on the back
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment