Variable wont change my class, sets it to zero? (toxiclibs waves)
in
Contributed Library Questions
•
1 year ago
I'm using the Toxiclibs library, started from the example of additive waves.
I've underlined and bolded where the problem is.
I want to change the frequency of the square wave by moving the mouse in the X direction.
I think it has something to do with the fact that I'm making the waves in the void setup so that it only occurs one time, but i don't know how to fix it :/
Help would be MUCH appreciated! :)
CODE:
AbstractWave waveX,waveY,waveV,waveW;
void setup() {
....
waveX=createSquareWave();
waveY=createConstantWave();
waveV=createSineWave();
waveW=createConstantWave();
.....
}
void draw() {
//D2 = mouseX;
background(0);
pushMatrix();
translate(0, height*0.5, 0);
rotateX(PI/2);
rotateZ(0);
// scale(0.5);
// Square golf
float prevY = waveY.update();
float colPrevY = 0;
waveY.push();
for(int y = 0; y < PIM; y += STEP2) {
float valueY = waveY.update();
float colY = valueY * 128 + 128;
waveX.push();
beginShape(TRIANGLE_STRIP);
for(int x = BEGIN; x < BEGIN+DIM; x += STEP1) {
float valueX = waveX.update();
float colX = valueX * 128 + 128;
fill(255);
vertex(x - D2, y - STEP2 - D2, (valueX + prevY) * AMP);
fill(255);
vertex(x - D2, y - D2, (valueX + valueY) * AMP);
}
endShape();
waveX.pop();
prevY = valueY;
colPrevY = colY;
}
waveY.pop();
waveX.update();
waveY.update();
//D2 = mouseX;
background(0);
pushMatrix();
translate(0, height*0.5, 0);
rotateX(PI/2);
rotateZ(0);
// scale(0.5);
// Square golf
float prevY = waveY.update();
float colPrevY = 0;
waveY.push();
for(int y = 0; y < PIM; y += STEP2) {
float valueY = waveY.update();
float colY = valueY * 128 + 128;
waveX.push();
beginShape(TRIANGLE_STRIP);
for(int x = BEGIN; x < BEGIN+DIM; x += STEP1) {
float valueX = waveX.update();
float colX = valueX * 128 + 128;
fill(255);
vertex(x - D2, y - STEP2 - D2, (valueX + prevY) * AMP);
fill(255);
vertex(x - D2, y - D2, (valueX + valueY) * AMP);
}
endShape();
waveX.pop();
prevY = valueY;
colPrevY = colY;
}
waveY.pop();
waveX.update();
waveY.update();
}
AbstractWave createSquareWave() {
AbstractWave w=null;
AbstractWave fmod=new ConstantWave(0);
w = new FMSquareWave(0, mouseX, 1, 0, fmod);
return w;
}
AbstractWave createConstantWave() {
AbstractWave w=null;
w = new ConstantWave(0);
return w;
}
AbstractWave w=null;
AbstractWave fmod=new ConstantWave(0);
w = new FMSquareWave(0, mouseX, 1, 0, fmod);
return w;
}
AbstractWave createConstantWave() {
AbstractWave w=null;
w = new ConstantWave(0);
return w;
}
1