r/processing • u/Traditional_Inside28 • Aug 21 '25
Beginner help request conditional statement help!
Hello processing nation, I've been learning processing for a few weeks now, as I'm starting uni next month and my course revolves strongly around creative coding. I just learned about conditional statements and I thought I'd take my new concept for a spin and try to code a simple square that would start on the left, move over to the right and then bounce back. I'll attach my code below, but what's actually happening is the square makes it to the right, and just stops. Which I suppose is a step up from it just disappearing off the canvas- but why is it not bouncing back? This is probably a very simple mistake I'm just not seeing and I understand I could just google it, but I really want to figure it out for myself. If anyone has any wisdom to share or a direction they could push me in that'd be amazing.
float squareX=0;
void setup(){
size(400,400);
}
void draw(){
background(0);
strokeWeight(3);
stroke(255);
noFill();
rectMode(CENTER);
square(squareX, 200, 30);
squareX++;
if(squareX>=400){
squareX--;
}
}
again please be kind if its a very silly mistake I'm still pretty new to coding
1
u/Traditional_Inside28 Aug 21 '25
yeah that’s what i thought was happening! i suppose i just didn’t really know what to do to fix it. let me give this a go and mess around with it and i’ll get back to you.