xxxxxxxxxx
int nbLines = 10, nbPts = 80;
float h, step;
float[] periods = new float[nbLines];
float[] speeds = new float[nbLines];
float[] offsets = new float[nbLines];
float[] amplitudes = new float[nbLines];
float [] prevys = new float[nbPts+1];
void setup() {
size(450, 450, P2D);
noFill();
colorMode(HSB, 1);
strokeWeight(8);
step = width / float(nbPts);
mousePressed();
}
void draw() {
background(1);
for (int i = 0; i < nbLines; i++) {
offsets[i] += speeds[i];
beginShape();
stroke(0);
for (int j = 0; j <= nbPts; j++) {
float x = step * j;
float y;
if (i == 0) {
y = i * 2 * h + h * sin(offsets[i] + float(j)/periods[i]) + h;
} else {
y = max(prevys[j] + 10, i * 2 * h + amplitudes[i] * sin(offsets[i] + float(j)/periods[i]) + h);
}
prevys[j] = y;
vertex(x, y);
}
endShape();
}
}
void mousePressed() {
nbLines = (int)random(5, 10);
h = height / nbLines / 2;
for (int i = 0; i < nbLines; i++) {
periods[i] = random(12, 102);
speeds[i] = random(.05, .15) * (i%2 == 0 ? 1 : -1);
offsets[i] = random(123);
amplitudes[i] = random(2, .5) * h;
}
}