I am using Processing and I’m completely stuck with this part of my code. Please any help is appreciated!?

Here is the void draw() portion of my code. The commented out (//) part is what is causing the problem. The program runs without the faulty code but i need this code for it to work. The error says there is too many ‘{‘ for ‘}’ but there are definitely an equal amount! Please help, thanks a lot

void draw(){
background(255);
for(int a = 1; a <= nRowsColumns; a++){
line(0,interval*a,3,interval*a);
line(interval*a,0,interval*a,3);
}
//noStroke();
fill(0,0,255);
rect(sourceX,sourceY,interval,interval);
fill(0,255,0);
rect(destinationX,destinationY,interval,…
if(destinationX != sourceX && destinationY != sourceY){
if(posX){
for(float a=sourceX+interval;a<destinationX;a+=int…
fill(random(255),random(255),random(255)…
rect(a,sourceY,interval,interval);
}
if(posY){
for(float b=sourceY;b<destinationY;b+=interval){
fill(random(255),random(255),random(255)…
rect(destinationX,b,interval,interval);
}//else{
// for(float b=sourceY;b>destinationY;b-=interval){
// fill(random(255),random(255),random(255)…
// rect(destinationX,b,interval,interval);
// }
//}
}
}else{
for(float a=sourceX-interval;a>destinationX;a-=int…
fill(random(255),random(255),random(255)…
rect(a,sourceY,interval,interval);
}
for(float b=sourceY;b>destinationY;b-=interval){
fill(random(255),random(255),random(255)…
rect(destinationX,b,interval,interval);
}
}
}
}

✅ Answers

  • Answerer 1

    The problem is here:

    if(posY)
    {
    __for(float b=sourceY;b<destinationY;b+=interval)
    __{
    ____fill(random(255),random(255),rando…
    ____rect(destinationX,b,interval,inter…
    __} //else{ <——- Invalid else. There is a missing ‘}’ before it.

    The else statement is being tied to the for loop, which is not valid. If you want to tie it to the if statement, you need to close the if block first.

    I recommend you line up your ‘{‘ and ‘}’ vertically to verify the code is written correctly. From what I can see, you have an equal amount of brackets, but they don’t make much sense where you have them.

  • Leave a Comment