# Trying to use coordinates from an array to draw an ellipse gives "The method ellipse(float, float, float, float) in the type PApplet is not applicable for the arguments (float\[\], float\[\], float, float)"

**URL:** <https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [March 2, 2020, 10:54am UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306 "2020-03-02T10:54:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dadagnos](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dadagnos](https://discourse.processing.org/u/Dadagnos)\
**Post date:** [March 2, 2020, 10:54am UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/1 "2020-03-02T10:54:02Z")

</div>

So at school we are learning to program now using processing, and one of the homework assignments is to draw several ellipses using a preformatted piece of code:

```auto
int[][] circles = { {10, 15}, {100, 130}, {77, 43}, {30, 145}, {185, 17}, {99, 76} }; 
final int DIAMETER = 20; 
final int YELLOW = #FFFF00; 
final int RED = #FF0000; 

void setup() {   
  size(200, 200);   
  ellipseMode(CORNER);
} 

void draw() {   
  background(#000000);
  drawCircles(circles);
} 

```

We are not allowed to change anything in it but we need to draw all the ellipses by writing a drawCircles() function. Now I have tried to get mine to work for days and asked my fellow students for help as well but the solution eludes me… here’s what I have so far:

```auto
void drawCircles(int[][] array) {
  for (int i =0; i <= array.length; i++) {
    for (int j =0; j <= array.length; j++) {
      fill(YELLOW);
      float[] x = float(array[i]);
      float[] y = float(array[j]);
      ellipse( x, y, (float)DIAMETER, (float)DIAMETER);
    }
  }
}

```

Whatever I try it keeps giving me errors; mostly about not entering floats into the ellipse() function therefore I have been trying to convert them using many different methods… Could someone perhaps point me in the right direction?

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [March 2, 2020, 11:20am UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/2 "2020-03-02T11:20:00Z")

</div>

Just taking a fast look, it seems that you are passing an array, not a float

> [@Dadagnos](#):
>
> float x = float(array[i]); float y = float(array[j]); ellipse( x, y, (float)DIAMETER, (float)DIAMETER);

x is a float array, same with y

If you want to give the coordinates x y from the array, you don’t need the second for:

```auto
void drawCircles(int[][] array) {
  for (int i =0; i < array.length; i++) {
      fill(YELLOW);
      float x = float(array[i][0]);
      float y = float(array[i][1]);
      ellipse( x, y, (float)DIAMETER, (float)DIAMETER);
  }
}

```

With `float(array[i])` you are acceding to ` { {x, y},.......}`, not the x value or the y, so the ellipse method is receiving something like this `ellipse( {10,15}, {100,130} ,(float)DIAMETER,(float)DIAMETER); `, instead of `ellipse(10, 15 ,(float)DIAMETER,(float)DIAMETER); `

Hope this helps you 😃

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 2, 2020, 4:16pm UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/3 "2020-03-02T16:16:41Z")

</div>

> [@Dadagnos](#):
>
> … I have been trying to convert them using many different methods…

There’s no need to coerce `int` values to `float` b/c Java automatically does that for us. 😉

Instead what you actually have to do is extract 1D `int[]` arrays outta your 2D `int[][]` 1.

The easiest way to pull that out is use an “enhanced” `for ( : ) ` loop type:

> **[for / Reference](https://processing.org/reference/for.html)**
>
> Controls a sequence of repetitions. A basic for structure has three parts: init, test, and update. Each part must be separated by a semicolon (;). The loop continues until …

Let’s say your **drawCircles()**'s 2D `int[][]` parameter is named _arr2d_:  
`void drawCircles(final int[]... arr2d) {}`

So you have to loop over that _arr2d_ in such a way that in each iteration of it we get a 1D `int[]` array from it.

Let’s name the iterator variable as _arr1d_ and declare it as datatype `int[]`:  
`for (final int[] arr1d : arr2d) {}`

Given parameter _arr2d_ actually points to the passed argument _circles_:  
`drawCircles(circles);`

You can be sure that in each iteration the iterator _arr1d_ is a 1D `int[]` array w/ _length_ = 2.

Then you’ve got exactly indices `[0]` & `[1]` from _arr1d_.

So you can finally access those 2 indices like this: `circle(arr1d[0], arr1d[1], DIAMETER);`

That’s it! If you didn’t understand some point of it, just ask again. 😇

---

<div class="post-metadata">

**Author:** ![Dadagnos](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dadagnos](https://discourse.processing.org/u/Dadagnos)\
**Post date:** [March 3, 2020, 8:48pm UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/4 "2020-03-03T20:48:48Z")

</div>

Thank you Waboqueox! That explains it!

---

<div class="post-metadata">

**Author:** ![Dadagnos](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dadagnos](https://discourse.processing.org/u/Dadagnos)\
**Post date:** [March 3, 2020, 8:54pm UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/5 "2020-03-03T20:54:10Z")

</div>

Wow…thanks GoTo! This concept is still a bit hard to grasp for me but I think I’m beginning to understand what you are talking about here. I’ll have to study it some more before I’ll know for sure though, but a definite ‘thank you’ for taking the time to address this!

---

<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:** [March 3, 2020, 9:17pm UTC](https://discourse.processing.org/t/trying-to-use-coordinates-from-an-array-to-draw-an-ellipse-gives-the-method-ellipse-float-float-float-float-in-the-type-papplet-is-not-applicable-for-the-arguments-float-float-float-float/18306/6 "2020-03-03T21:17:22Z")

</div>

here is a version that gets the 1D arrays from the 2D array and prints them

```auto

int[][] circles = { 
  {10, 15}, 
  {100, 130}, 
  {77, 43}, 
  {30, 145}, 
  {185, 17}, 
  {99, 76} 
}; 
final int DIAMETER = 20; 
final int YELLOW = #FFFF00; 
final int RED = #FF0000; 

void setup() {   
  size(200, 200);   
  ellipseMode(CORNER);
} 

void draw() {   
  background(#000000);
  for (int[] arr1d : circles) {
    printArray(arr1d);
  }
  exit();
}

```

And circles

```auto
 

int[][] circles = { 
  {10, 15}, 
  {100, 130}, 
  {77, 43}, 
  {30, 145}, 
  {185, 17}, 
  {99, 76} 
}; 
final int DIAMETER = 20; 
final int YELLOW = #FFFF00; 
final int RED = #FF0000; 

void setup() {   
  size(200, 200);   
  ellipseMode(CORNER);
} 

void draw() {   
  background(#000000);
  for (int[] arr1d : circles) {
    ellipse(arr1d[0], arr1d[1], DIAMETER, DIAMETER);
  }
}

```
