Phase difference between waves
in
Programming Questions
•
1 year ago
Hi,
In the following simple sound wave simulation the compression lags behind the wave slightly, by about 1/8 of a wavelength. Is there any smple way to correct this? I've tried but only been able to move the wave left a bit but that's not correct.
In the following simple sound wave simulation the compression lags behind the wave slightly, by about 1/8 of a wavelength. Is there any smple way to correct this? I've tried but only been able to move the wave left a bit but that's not correct.
- int numDots = 400;
- int amplitude = 30;
- float frequency = PI/30; //
- float increment = 1;
- float xPos, xPosLine;
- float vel = 0.01;
- float xIncr = (width-50-amplitude)/numDots;
- int[]ArrayX = new int[numDots];
- int[]ArrayY = new int[numDots];
- float[]XsinVal = new float[numDots];
- float[]angle = new float[numDots];
- void setup() { size (600, 300);
- for (int i = 0; i < numDots; i++) {
- ArrayX[i] = (int) random(50, width-amplitude);
- ArrayY[i] = (int) random(30, height/2);
- }
- }
- void draw() { frameRate(24);
- background (33, 204, 232);
- noStroke();
- fill(24, 35, 234);
- for (int i = 0; i < numDots; i++) {
- XsinVal[i] = sin(angle[i])*amplitude;
- ellipse(ArrayX[i] + XsinVal[i], ArrayY[i], 3, 3);
- if (xPos > ArrayX[i]) {
- angle[i] += frequency;
- }
- ellipse(ArrayX[i], XsinVal[i] + 230, 3, 3);
- stroke(250, 0, 0);
- fill(0);
- ellipse(xPos, 100, 3, 3);
- noStroke(); fill(0);
- xPos += vel;
- fill(24, 35, 234);
- }
- }
- boolean bStop;
- void keyPressed() {
- bStop = !bStop;
- if (bStop) noLoop();
- else loop();
- }
Thanks,
Shane
1