> For the complete documentation index, see [llms.txt](https://easy-draw.joemazzone.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easy-draw.joemazzone.net/java/module-reference/drawing-shapes.md).

# Drawing Shapes

When drawing shapes, the sequence matters. That is how the layering system works.

The first object that is drawn in your code will be at the bottom most layer of your drawing. The last object that is drawn in your code will be the top most layer of your drawing.

Shapes are made with `new EasyDraw.ShapeName(...)` and the required values in order. Optional properties are changed with setters after the shape is made.

These setters work on every shape except `Line`, `Text`, and `Image`:

| Setter                                              | Default | Description                                                            |
| --------------------------------------------------- | ------- | ---------------------------------------------------------------------- |
| `setColor(color)` / `setColor(r, g, b)`             | "black" | The color of the shape.                                                |
| `setBorderColor(color)` / `setBorderColor(r, g, b)` | null    | Color of the border. Use `null` for no border.                         |
| `setBorderWidth(width)`                             | 0       | Size of the border in pixels.                                          |
| `setDashes(size)`                                   | 0       | Size of the dashes for the border in pixels. Use 0 for a solid border. |
| `setVisible(visible)`                               | true    | true = Shape can be seen. false = Shape cannot be seen.                |

## Rectangle

`new EasyDraw.Rectangle(x, y, width, height)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_X4Wtqc7FkpTp_iKw%2F-MR_brBio-EXXyHCGBw8%2Fimage.png?alt=media\&token=a11a1446-bff5-41de-bb68-69687d7b414d)

| Value    | Description                                                |
| -------- | ---------------------------------------------------------- |
| `x`, `y` | The x and y coordinate of the rectangle's top-left corner. |
| `width`  | The width of the rectangle in pixels.                      |
| `height` | The height of the rectangle in pixels.                     |

Getters and setters: `getX()`, `getY()`, `setXY(x, y)`, `setX(x)`, `setY(y)`, `getWidth()`, `setWidth(width)`, `getHeight()`, `setHeight(height)`

Example:

```java
EasyDraw.Rectangle rect1 = new EasyDraw.Rectangle(300, 300, 200, 150);
rect1.setColor(255, 0, 0);       // Optional
rect1.setBorderColor(0, 0, 0);   // Optional
rect1.setBorderWidth(10);        // Optional
rect1.setDashes(25);             // Optional
```

{% hint style="info" %}
A Rectangle can rotate around its center or its top-left corner: `rect1.rotate(45, true)`
{% endhint %}

## Regular Polygon

`new EasyDraw.RegPolygon(nsides, centerX, centerY, radius)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_X4Wtqc7FkpTp_iKw%2F-MR_cru4Phqg61haLd1f%2Fimage.png?alt=media\&token=328f7cf3-9628-43e9-ad94-853cd45011f1)

| Value                | Description                                                |
| -------------------- | ---------------------------------------------------------- |
| `nsides`             | The number of sides the polygon has (3 or more).           |
| `centerX`, `centerY` | The x and y coordinate of the polygon's center.            |
| `radius`             | The distance in pixels from the center to any outer point. |

Getters and setters: `getNsides()`, `setNsides(nsides)`, `getCenterX()`, `getCenterY()`, `setCenter(x, y)`, `getRadius()`, `setRadius(radius)`

Example:

```java
EasyDraw.RegPolygon octagon = new EasyDraw.RegPolygon(8, 300, 300, 100);
octagon.setColor(255, 0, 0);     // Optional
```

## Polygon

`new EasyDraw.Polygon(x1, y1, x2, y2, x3, y3, ...)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_cunQqfAZ7Fzz-G2D%2F-MR_fjwaZO4mP9XlS2rC%2Fimage.png?alt=media\&token=5780ee7e-667c-4a32-b299-a95d92b83d35)

Give the x and y coordinates of each point, in order. The Polygon can have as many sides as you want. There MUST be an even number of values.

Getters and setters: `getPoints()`, `setPoints(x1, y1, x2, y2, ...)`

Example:

```java
EasyDraw.Polygon poly1 = new EasyDraw.Polygon(25, 25, 150, 25, 200, 200, 100, 250, 25, 200);
poly1.setColor(255, 0, 0);       // Optional
poly1.setBorderColor(0, 0, 0);   // Optional
poly1.setBorderWidth(10);        // Optional
```

You can also give the points as a `double[]` array:

```java
double[] points = {25, 25, 150, 25, 200, 200};
EasyDraw.Polygon triangle = new EasyDraw.Polygon(points);
```

## Line

`new EasyDraw.Line(x1, y1, x2, y2)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MU-P9t60n8INhnBrz6e%2F-MU-ZaAMGoIFqzFnz8El%2Fimage.png?alt=media\&token=433a7851-d0ce-4911-8bdf-3488daa6d6fe)

Give more x y coordinates to draw a line through many points:

`new EasyDraw.Line(x1, y1, x2, y2, x3, y3, ...)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MU-P9t60n8INhnBrz6e%2F-MU-ZJGBV1J0VGjttyKV%2Fimage.png?alt=media\&token=2cf2488d-c786-45e1-87a8-0153e6d938ce)

| Setter                                  | Default | Description                                                                 |
| --------------------------------------- | ------- | --------------------------------------------------------------------------- |
| `setColor(color)` / `setColor(r, g, b)` | "black" | The color of the line.                                                      |
| `setThickness(thickness)`               | 5       | The width of the line in pixels.                                            |
| `setDashes(size)`                       | 0       | Size of the dashes in pixels. Use 0 for a solid line.                       |
| `setArrowStart(true)`                   | false   | Add an arrow to the start of the line.                                      |
| `setArrowEnd(true)`                     | false   | Add an arrow to the end of the line.                                        |
| `setStyle(style)`                       | "round" | `"round"` for round edges and joints and `"cut"` for squared/cut-off edges. |
| `setVisible(visible)`                   | true    | true = Line can be seen. false = Line cannot be seen.                       |

Other getters and setters: `getPoints()`, `setPoints(...)`, `setXY1(x, y)` (moves the start), `setXY2(x, y)` (moves the end)

Example:

```java
EasyDraw.Line line1 = new EasyDraw.Line(100, 100, 200, 200);
line1.setThickness(8);           // Optional
line1.setColor(255, 0, 0);       // Optional
line1.setDashes(25);             // Optional

EasyDraw.Line zigzag = new EasyDraw.Line(50, 500, 100, 450, 150, 500, 200, 450);
zigzag.setStyle("cut");          // Optional
zigzag.setArrowEnd(true);        // Optional
```

## Circle

`new EasyDraw.Circle(centerX, centerY, radius)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_gAyOFo4wA1T_3cRr%2F-MR_i0W_lHdud28t__p9%2Fimage.png?alt=media\&token=cd71f25b-7435-40c9-9c31-9ba540ba0a52)

| Value                | Description                                                          |
| -------------------- | -------------------------------------------------------------------- |
| `centerX`, `centerY` | The center coordinate of the circle.                                 |
| `radius`             | The measurement in pixels from the center of the circle to the edge. |

Getters and setters: `getCenterX()`, `getCenterY()`, `setCenter(x, y)`, `getRadius()`, `setRadius(radius)`

Example:

```java
EasyDraw.Circle cir1 = new EasyDraw.Circle(300, 300, 100);
cir1.setColor(255, 0, 0);        // Optional
cir1.setBorderColor(0, 0, 0);    // Optional
cir1.setBorderWidth(10);         // Optional
```

## Oval

`new EasyDraw.Oval(centerX, centerY, width, height)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_gAyOFo4wA1T_3cRr%2F-MR_ioK19DUZDAWjeepO%2Fimage.png?alt=media\&token=810c11cf-a128-4495-b61c-2224fdaaa984)

| Value                | Description                                                   |
| -------------------- | ------------------------------------------------------------- |
| `centerX`, `centerY` | The center coordinate of the oval.                            |
| `width`              | The measurement in pixels of the left edge to the right edge. |
| `height`             | The measurement in pixels of the top edge to the bottom edge. |

Getters and setters: `getCenterX()`, `getCenterY()`, `setCenter(x, y)`, `getWidth()`, `setWidth(width)`, `getHeight()`, `setHeight(height)`

Example:

```java
EasyDraw.Oval oval1 = new EasyDraw.Oval(300, 300, 100, 200);
oval1.setColor(255, 0, 0);       // Optional
```

## Arc

`new EasyDraw.Arc(centerX, centerY, width, height, sweepAngle)`

![](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRAMSGwqRIdQ2ADsTkz%2F-MR_j3WiqNf06YQqsd1G%2F-MR_nS8Sjg0QA5oZFX7U%2Fimage.png?alt=media\&token=3d9458ea-cdd3-4dd7-b3e8-288e347ff887)

There are 3 different styles, set with `setStyle()`: `"pieslice"` (the default), `"chord"`, and `"arc"`.

![](https://tkdocs.com/shipman/img/chord.png)

*Note: The "arc" style is only an outline. It uses the border color (or the color if there is no border color) and the border width (at least 1 pixel).*

| Value                | Description                                                               |
| -------------------- | ------------------------------------------------------------------------- |
| `centerX`, `centerY` | The center coordinate of the circle used to create the arc.               |
| `width`              | The width of the circle used to create the arc.                           |
| `height`             | The height of the circle used to create the arc.                          |
| `sweepAngle`         | The amount of the arc to show. From 0 to the angle in degrees identified. |

Getters and setters: `getCenterX()`, `getCenterY()`, `setCenter(x, y)`, `getWidth()`, `setWidth(width)`, `getHeight()`, `setHeight(height)`, `getSweepAngle()`, `setSweepAngle(angle)`, `getStyle()`, `setStyle(style)`

Example:

```java
EasyDraw.Arc arc1 = new EasyDraw.Arc(300, 300, 100, 100, 90);
arc1.setStyle("chord");          // Optional
arc1.setColor(255, 0, 0);        // Optional
```
