why these if statements doesnt work?
in
Programming Questions
•
10 months ago
i want to reverse the motion with this condition but this doesn't work, i cant see why
if(n>50){speedX=speedX*-1;};
if(n<-50){speedX=speedX*-1;};
if(n>50){speedX=speedX*-1;};
if(n<-50){speedX=speedX*-1;};
- float n;
void setup(){
size(768,576);
frameRate(12);
smooth();
stroke(0);
}
void stripes(float speedX) {
n=n+speedX;
// this should reverse the motion, no?
if(n>50){speedX=speedX*-1;};
if(n<-50){speedX=speedX*-1;};
for (int i=-20;i<width+50;i+=10)
{
line(i,0,n+i,30);
};
}
void draw(){
background(255);
stroke(0);
stripes(1);
}
1