# Connect only every third circle

**URL:** <https://discourse.processing.org/t/connect-only-every-third-circle/33798>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [November 28, 2021, 3:11pm UTC](https://discourse.processing.org/t/connect-only-every-third-circle/33798 "2021-11-28T15:11:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristina](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@Kristina](https://discourse.processing.org/u/Kristina)\
**Post date:** [November 28, 2021, 3:11pm UTC](https://discourse.processing.org/t/connect-only-every-third-circle/33798/1 "2021-11-28T15:11:18Z")

</div>

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);
}

```

}  
}  
\<

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 28, 2021, 4:12pm UTC](https://discourse.processing.org/t/connect-only-every-third-circle/33798/2 "2021-11-28T16:12:37Z")

</div>

Hello,

the [modulo operator](https://processing.org/reference/modulo.html) is useful for checking for intervals within a loop:

> **[What is the Modulus Operator? A Short Guide with Practical Use Cases |...](https://blog.mattclemente.com/2019/07/12/modulus-operator-modulo-operation/)**
>
> Always trying to be better

`:)`

---

<div class="post-metadata">

**Author:** ![Kristina](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@Kristina](https://discourse.processing.org/u/Kristina)\
**Post date:** [November 28, 2021, 5:09pm UTC](https://discourse.processing.org/t/connect-only-every-third-circle/33798/3 "2021-11-28T17:09:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kristina](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@Kristina](https://discourse.processing.org/u/Kristina)\
**Post date:** [November 28, 2021, 7:12pm UTC](https://discourse.processing.org/t/connect-only-every-third-circle/33798/4 "2021-11-28T19:12:55Z")

</div>

Update i finally figure it out 🙂
