---
title: "polygon"
description: "A regular polygon with any number of sides."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "shape"
categorySlug: "shape"
categoryTitle: "Shapes"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/shape.ts#L87"
---

# polygon

A regular polygon with any number of sides.

```ts
polygon(x: Val, y: Val, radius: Val, sides: Val): Expr
```

Import `shape` from `shaders/std` and use `shape.polygon`.

`radius` is the distance from the centre to the middle of each side (not to the corners), in uv. `sides` is the side count, 3 for a triangle and up. A flat side faces right at rotation 0.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `x` | `Val` |  |
| `y` | `Val` |  |
| `radius` | `Val` |  |
| `sides` | `Val` |  |

## Example

```ts
shape: {distance: ({x, y}, u) => polygon(x, y, u('radius'), u('sides')), …}
```

> **Tip.** `math.mix(polygon(…), circle(…), u('rounding'))` morphs the corners away.

## See also

- [`star`](/docs/primitives/shape/star) — A star with straight sides and sharp points.
- [`flower`](/docs/primitives/shape/flower) — A flower with pointed petals and V-shaped valleys between them.
- [`circle`](/docs/primitives/shape/circle) — A circle of a given radius.

## Used by

[Polygon](/docs/components/polygon)