# Passing multiple values between methods/classes

**URL:** <https://discourse.processing.org/t/passing-multiple-values-between-methods-classes/12605>\
**Category:** Coding Questions\
**Created:** [July 9, 2019, 3:24am UTC](https://discourse.processing.org/t/passing-multiple-values-between-methods-classes/12605 "2019-07-09T03:24:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cardori](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cardori/32/5765_2.png) [@cardori](https://discourse.processing.org/u/cardori)\
**Post date:** [July 9, 2019, 3:24am UTC](https://discourse.processing.org/t/passing-multiple-values-between-methods-classes/12605/1 "2019-07-09T03:24:19Z")

</div>

Hi.  
I’m creating an Hexagonal grid  
I have the points for creating it already(edges). The method cell calculates the creation of one hexagon and then it is passed to the method grid where the grid is created. The problem is I cannot get the values of all the edges(x,y) created within the grid method. I tried using an ArrayList to save all the edges but I´m getting incomplete values.  
I need the edges of the complete grid in order to use them in a more general class.  
I know the grid is calculated correctly because I can draw it if I uncomment the code from lines 31 to 35.

Any suggestion would be greatly appreciated  
Thanks

```auto
Hexagon h;

void setup() {
  size(500, 500);
  h= new Hexagon();
  h.grid();
}

class Hexagon {

  int sides;
  PVector[]edges;
  int size;

  Hexagon() {
    size=30;
    sides=6;
    edges= new PVector[sides];
  }

  void cell(float cenX, float cenY) {

    for (int i=0; i<sides; i++) {
      float angle_deg=60*i-30;
      float angle_rad= PI/180*angle_deg;
      float edX= cenX+size*cos(angle_rad);
      float edY= cenY+size*sin(angle_rad);

      edges[i]= new PVector(edX, edY);
    }
    //DRAWING HEXAGONAL GRID TEST
    //for (int i =0; i<sides-1;i++){
    //line(edges[i].x, edges[i].y, edges[i+1].x, edges[i+1].y);
    //line(edges[5].x, edges[5].y, edges[0].x, edges[0].y);
    //}
  }

  ArrayList<PVector> grid() {

    ArrayList <PVector> gridPts= new ArrayList <PVector>();
    float h=2*size;
    float w=(sqrt(3))*size;
    float vertCent=h*0.75;
    int row=0;

    for (float cenY=h/2; cenY<250; cenY+=vertCent)
    {
      float offX= ((row%2)==0) ? w:w/2;

      for (float cenX=offX+50; cenX<250; cenX+=w)
      {
        cell(cenX, cenY);

        gridPts.add(new PVector(cenX, cenY));
      }
      row++;
    }
    println(gridPts.get(0)); /////INCOMPLETE VALUES
    return gridPts;
  }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [July 12, 2019, 7:59pm UTC](https://discourse.processing.org/t/passing-multiple-values-between-methods-classes/12605/2 "2019-07-12T19:59:21Z")

</div>

> [@cardori](#):
>
> The problem is I cannot get the values of all the edges(x,y) created within the grid method.

Were you able to resolve this issue?

I’m a bit confused by the example code. Is class Hexagon for a single hexagon, or for a grid of hexagons? Is your only goal to draw the lines of a hexagonal mesh, or do you want to do anything else with it – like give different tiles different fills or outline colors, or change the scale, or merge pieces et cetera?
