while loop problem
in
Programming Questions
•
1 year ago
Hello,
I´m another newbee in processing and programming.
I have a problem with the while loop, I want the loop "open the windowflaps" in my picture. Till now they are only closed. I would like to use a while loop, so while the cursor is close to or directly on the window, the flap-area just change it´s position directly next to it´s window (like as it´s would be opend to the right / =+ 50 on x axis) and you can see the "glass".
But only of that one window, not all the windowflaps!
I don´t even know if the while loop is right here. Maybe this is a super easy question but i just don´t get it.
I would be happy to get a clue or solution to my problem by one of you, thanks!
Here´s my sketch:
int nr = 4; // Anzahl
float fpx = 50; // flapposition x
float fpy = 50; // flapposition y
float nfpn = fpx+50; // new flapposition
void setup() {
size(600, 600);
background(9,84,47);
smooth();
}
void draw() {
for (int i=0; i< nr; i++){
for (int j=0; j< nr; j++){
window (i*(width/nr),j*(height/nr));
flap (i*(width/nr),j*(height/nr));
float d = dist(fpx,fpy, mouseX, mouseY); // I THINK I fpx AND fpy ARE NOT RIGHT HERE. I DON´T KNOW WHAT TO PUT.
while (d < 10)
{
fpx = nfpn;
}
}
}
}
void window (float x, float y)
{
pushMatrix();
translate(x, y);
stroke(255);
strokeWeight(3);
fill(182,218,234);
rect(50,50,40,60);
noFill();
stroke(255);
strokeWeight(3);
line(70,51,70,109);
line(51,80,89,80);
popMatrix();
}
void flap (float x, float y)
{
pushMatrix();
translate(x, y);
fill(95,64,40);
rect(fpx,fpy,40,60);
popMatrix();
}
I´m another newbee in processing and programming.
I have a problem with the while loop, I want the loop "open the windowflaps" in my picture. Till now they are only closed. I would like to use a while loop, so while the cursor is close to or directly on the window, the flap-area just change it´s position directly next to it´s window (like as it´s would be opend to the right / =+ 50 on x axis) and you can see the "glass".
But only of that one window, not all the windowflaps!
I don´t even know if the while loop is right here. Maybe this is a super easy question but i just don´t get it.
I would be happy to get a clue or solution to my problem by one of you, thanks!
Here´s my sketch:
int nr = 4; // Anzahl
float fpx = 50; // flapposition x
float fpy = 50; // flapposition y
float nfpn = fpx+50; // new flapposition
void setup() {
size(600, 600);
background(9,84,47);
smooth();
}
void draw() {
for (int i=0; i< nr; i++){
for (int j=0; j< nr; j++){
window (i*(width/nr),j*(height/nr));
flap (i*(width/nr),j*(height/nr));
float d = dist(fpx,fpy, mouseX, mouseY); // I THINK I fpx AND fpy ARE NOT RIGHT HERE. I DON´T KNOW WHAT TO PUT.
while (d < 10)
{
fpx = nfpn;
}
}
}
}
void window (float x, float y)
{
pushMatrix();
translate(x, y);
stroke(255);
strokeWeight(3);
fill(182,218,234);
rect(50,50,40,60);
noFill();
stroke(255);
strokeWeight(3);
line(70,51,70,109);
line(51,80,89,80);
popMatrix();
}
void flap (float x, float y)
{
pushMatrix();
translate(x, y);
fill(95,64,40);
rect(fpx,fpy,40,60);
popMatrix();
}
1