# 2D Array Help needed

**URL:** <https://discourse.processing.org/t/2d-array-help-needed/8567>\
**Category:** Coding Questions\
**Created:** [February 20, 2019, 2:45pm UTC](https://discourse.processing.org/t/2d-array-help-needed/8567 "2019-02-20T14:45:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 20, 2019, 2:45pm UTC](https://discourse.processing.org/t/2d-array-help-needed/8567/1 "2019-02-20T14:45:32Z")

</div>

Hi, I am hoping someone can help me again with my Processing assignment. This is a red and black checker board. The question is “add one line of code that will create a circle using the ellipse function and place it on the black square as shown by the illustration.”

Here is what I have so far. The last line is the one that I can’t figure out. Thanks in advance for any help.

```auto
int squareSize = 50; // Dimensions ask for 40x40 
int cols, rows;

void setup() {

  size(500, 500); // Specified by assignment
 
  // Initialize columns and rows
  cols = 10; // Specified by assignment | size/squareSize
  rows = 10; // Specified by assignment | size/squareSize
}
 
void draw() {
 
  // Begin loop for columns
  for (int i = 0; i < cols; i++) {
    // Begin loop for rows
    for (int j = 0; j < rows; j++) {
 
      // Scaling up to draw a rectangle at (x,y)
      int x = i*squareSize; // width
      int y = j*squareSize; // height
 
      // Begin fill controls
      if ((i+j) % 2 == 0) { // Even is red
        fill(250, 0, 0);
      } else { // Odd is black
        fill(0);
      }
 
      // For every column and row, a rectangle is drawn at an (x,y) location scaled and sized by videoScale.
      rect(x, y, squareSize, squareSize);
      fill(0,0,0);
        fill(255);
      ellipse(x,y, 40,40); **// How do I move these to be only in the black squares?**
    
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 20, 2019, 11:48pm UTC](https://discourse.processing.org/t/2d-array-help-needed/8567/2 "2019-02-20T23:48:45Z")

</div>

> [@Awal](#):
>
> and place it on the black square as shown by the illustration.”

does it mean one circle over each black field  
( like you try over every field what could work if your white is same!  
means the white circle in the white fields would be not visible. )

or does it mean one circle on a specific field?

anyhow  
two fill commands / first black then white / not make sense  
and fill fill ellipse are 3 lines???

and pls. repair your code posting using

```auto
</>

```

code formatting.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 21, 2019, 10:26am UTC](https://discourse.processing.org/t/2d-array-help-needed/8567/3 "2019-02-21T10:26:35Z")

</div>

> [@Awal](#):
>
> How do I move these to be only in the black squares?\*\*

The idea is to check whether you are in an even column plus uneven row or vice versa

You need an if clause :

`if ((i+j) % 2 == 0)`

or

`if(i%2==0 && j%2==0) {`

Chrisir
