# Example Code: PShape

The code below shows how to create a custom function that creates and returns a custom PShape object.  The PShape method: **shape(PShape s, float x, float y )**  is used in draw( ) to render the shape by inputing the specified values for parameters:  x, y:&#x20;

```java

void setup( ) {
  size( 600, 600);
  colorMode(HSB, 360, 100, 100, 100);//HSBA
  background(360);  //white
}

void draw( ) {
  color purple = color( 270, 100, 100); 
  float len = 100;
  if ( mousePressed) {
    translate( mouseX, mouseY); //move origin to mouse postion
    PShape s = createMyShape1( len, purple); //create PShape
    shape( s, 0, 0 ); //display at translated origin
    resetMatrix(); //move origin back to upper left
  }
}


PShape createMyShape1(  float len, color c1) {
  //fill( c1); //for some PShapes, use fill before creating the shape
  PShape s = createShape(RECT, 0, 0, len, len) ;
  s.setFill( c1);//for some PShapes, use setFill( ) after creating the shape

  return s;
}
```


---

# 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-1/pshape/sept-16-code.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.
