# Function: DisplayShapeMatrix()

In this section, we will refactor the code to create a custom function: displayShapeMatrix( ), that can render a 2D PShape array in a grid layout, at any x,y location.

The function below is used to determine the grid-layout, and actually calls the PShape `shape( )`function that is used to render each PShape object on the screen.

```java
void displayShapeMatrix(PShape[][] shapes,int rows, int cols, int size){
 int xPos=0;  
 int yPos=0;         
 for( int i=0; i< rows; i++){     
  for( int j=0; j< cols; j++){   
   shape(shapes[i][j], xPos, yPos);         
    xPos += size;      
    }  //end inner for-loop (j:cols)     
    xPos =0;       
    yPos += size;     
  } //end outer for-loop (i:rows)
 } //end function
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs1335/project-2/function-displayshapematrix.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
