# Connect only every third circle

Hey, i would really appreciate some help with an assignement i have to do. I had to create this picture of a row of circles at the top and bottom. Each circle is connected with the others at the Bottom or Top. This is the code i have and it works, but i dont understand what i should add or change if i for example only want every third red and blue circle to connect?

int diameter = 25; //Size of circles
int y1 = 25;
int y2 = 475;
int spacing = 50; //Spacing between circles
int x1 = 25;
int x2 = 25;

void setup () {
size(500, 500);
}

void draw () {

background(255);

//Draw red circles at top and blue circles at bottom
for (x1 = 25; x1 < width; x1 += spacing) {
fill (255, 0, 0);
ellipse (x1, y1, diameter, diameter);
fill (0, 0, 255);
ellipse (x1, y2, diameter, diameter);

``````//Draw Lines between circles
for (x2 = 25; x2 < width; x2 +=spacing) {

line(x1, y1, x2, y2);
}
``````

}
}
<

Hello,

the modulo operator is useful for checking for intervals within a loop:

`:)`

1 Like

Hi, thanks for the answer! Ive been trying to use it but somehow no matter where i use it it doesnt have the effect i want it to have… I guess i gotta try out some more. I managed to have only every third bottom circle connected but the red ones kinda dont work.

Update i finally figure it out 2 Likes