# Connected Circles

**URL:** <https://discourse.processing.org/t/connected-circles/7471>\
**Category:** Coding Questions\
**Created:** [January 13, 2019, 4:34pm UTC](https://discourse.processing.org/t/connected-circles/7471 "2019-01-13T16:34:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![german\_guy](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@german\_guy](https://discourse.processing.org/u/german_guy)\
**Post date:** [January 13, 2019, 4:34pm UTC](https://discourse.processing.org/t/connected-circles/7471/1 "2019-01-13T16:34:02Z")

</div>

Hey,

this is a task that I have to solve for a course at uni. It’s processing for beginners. We use Processing 3.

What do I do to connect each circle at y = 100 with those at y = 550? Apparently, a nested loop is a solution, but I have already tried and it didn’t work out for me.

This is what I have gotten so far. Below you can see a picture of what it is supposed to look like.

Appreciate your help.

Code:

```auto
size (1000,650);
background (255);
int spacing = 100;
int diameter = 50;
int x1 = -50;
int y1 = 100;
int y2 = 550;
int x2 = x1 += spacing;
ellipseMode (CENTER);
for (x1 = 50; x1 < width; x1 += spacing)
{
  fill (120); ellipse (x1,y1,diameter,diameter);
  ellipse (x1,y2,diameter,diameter);
  line (x1,y1,x2,y2);
  line (x2,y1,x1,y2);
}

```

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 13, 2019, 5:11pm UTC](https://discourse.processing.org/t/connected-circles/7471/2 "2019-01-13T17:11:28Z")

</div>

Please, when writing or editing a comment, use a little \</\> button above the text field to format your code into `monospace font, like this one`.

Anyways, I think it makes sense to get rid of `int x1` and `int x2` definitions, and replace `for(x1 =..` with `for(int x1 =..`, and then put another for loop inside of that one `for(int x2=..`. That second `for` loop is a nested one.  
Something like this:

```auto
size (1000, 650);
background (255);
int spacing = 100;
int diameter = 50;
int y1 = 100;
int y2 = 550;
ellipseMode (CENTER);
for (int x1 = 50; x1 < width; x1 += spacing)
{
  fill (120);
  ellipse (x1, y1, diameter, diameter);
  ellipse (x1, y2, diameter, diameter);
  for (int x2 = 50; x2 < width; x2 += spacing) {
    line (x1, y1, x2, y2);
  }
}

```

---

<div class="post-metadata">

**Author:** ![german\_guy](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@german\_guy](https://discourse.processing.org/u/german_guy)\
**Post date:** [January 13, 2019, 5:27pm UTC](https://discourse.processing.org/t/connected-circles/7471/3 "2019-01-13T17:27:30Z")

</div>

Thanks so much, Architector! However, seeing a possible solution, I realize I should have been able to figure that out, am a bit disappointed with myself haha. Also thank you for the advice on the formatting, this is my first post, so I didn’t know. Your help is much appreciated!!! Cheers ✌
