please format code with </> button * homework policy * asking questions
Hello! I’m quite new to this so this is probably really easy but I’ve made this rotating square that I want to, after having completed a certain percentage of the rotation, reverse direction and “swing back”. Then I want it to reverse direction again so it moves in the same direction again. Kind of like a pendulum (that’s not affected by gravity!).
I’ve tried to use if loops but I think I’m getting my maths confused because I told it to if <5, move forward and if>5 move backward, but of course, this means that it just freezes in place.
This is the code I have right now.
Thank you!
//moiree
int a = 0;
void setup(){
size(800, 800, P2D);
background(50);
}
void draw(){
background(50);
pushMatrix();
rotate(radians(a));
// if (a>5){
// a=5;
// a=a-0.05;
// };
if (a<5){
a=a+0.05;
}
for(float q=30; q<width -30; q=q+7){
stroke(255);
strokeWeight(2);
line(50,q, width-50, q);
};
popMatrix();
pushMatrix();
for(float c=30; c<width -30; c=c+7){
stroke(255);
strokeWeight(2);
line(50,c, width-50, c);
};
popMatrix();
print(a);
}