This will probably be easily answered by someone who knows more about the 'guts' then I do. I've cobble together the sketch below and am happy with it, except for one small bug. If I comment out the line noFill(); I get an array index error. Strange. Does it have something to do with the syntax, placing my vertices inside a 'for' loop, while beginShape() and endShape are outside?
Thanks in advance.
Code:
int largo;
float[] x;
float[] y;
float[] z;
int gap = 33;
float noiseX,noiseY,noiseZ,xoff,yoff,zoff,xwalk,ywalk,zwalk,mx2,my2,mz2;
int ind;
float xBin,yBin,avgX,avgY;
void setup(){
size(640,480,P3D);
noiseX = 0.012;
noiseY = 0.023;
noiseZ = 0.008;
largo = 221;
x=new float[largo];
y=new float[largo];
z=new float[largo];
}
void draw(){
xoff = xoff + noiseX;
yoff = yoff + noiseY;
zoff = zoff + noiseZ;
xwalk = sin(noise(xoff)) * width;
ywalk = sin(noise(yoff)) * height;
zwalk = noise(zoff) * height;
background(0);
noFill();
strokeWeight(0.5);
for(int i =1;i<largo;i++){
x[i-1] = x[i];
y[i-1] = y[i];
z[i-1] = z[i];
}
x[largo-1]=xwalk;
y[largo-1]=ywalk;
z[largo-1]=zwalk;
make();
}
void make(){
beginShape();
for(int i=0; i<largo; i++) {
stroke(i,12,198,i/3);
float mx = x[i];
float my = y[i];
float mz = z[i];
ind = constrain(i+gap,0,largo-1);
mx2 = x[ind];
my2 = y[ind];
mz2 = z[ind];
curveVertex(mx,my,-mz);
curveVertex(mx2,my2,-mz2);
}
endShape();
camFollow();
}
void camFollow(){
xBin = 0;
yBin = 0;
int largo_ = 55;
int plus = largo - largo_;
for (int i=0;i<largo_;i++){
xBin += x[i+plus];
yBin+= y[i+plus];
}
avgX = xBin/largo_;
avgY = yBin/largo_;
camera(xwalk,ywalk,100,
avgX,avgY,-300,
0.0,1.0,0);
spotLight(255,255,0,
avgX,avgY,300,
0,-0.5,-1,
PI, 2);
}
void saveFrames(int numFrames){
if (frameCount <= numFrames) {
saveFrame("woim-####.tif");
}
}