---
title: "Shapes"
description: "The 2D shapes: a circle, a star, a heart and a dozen more, each as a function of a point that tells you how far that point is from the shape's edge."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "shape"
categorySlug: "shape"
wordCount: 16
curated: true
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/shape.ts"
editUrl: "https://github.com/shader-effects-inc/shaders/edit/main/packages/core/docs/std/shape.md"
---

# Shapes

The 2D shapes: a circle, a star, a heart and a dozen more, each as a function of a point
that tells you how far that point is from the shape's edge. The number is a **signed
distance**: negative inside, zero on the edge, positive outside. Sizes are in uv, where 1 is
the canvas height.

A shape becomes a component through the `shape:` field of `defineShader`. Its `distance`
receives the shape-local point (already centred on the `center` prop, aspect-corrected,
rotated and y down) and `u('name')` for each of your size props, and returns one of these
words. `shapeProps` declares those size props. `bounds` names the props that size the
selection box in the editor. The engine adds the `center`, `rotation`, `color`, stroke and
softness props, the bounding box and the anti-aliased pixel mask, so a shape shader is a
few lines. Shapes also combine with `math`: `mix` two distances to morph between them,
`min` for a union, `max` for an intersection.

```ts
import {shape} from 'shaders/std'
```

## Reach for it when

| When you need | Use |
|---|---|
| a disc | [`circle`](/docs/primitives/shape/circle) |
| an oval | [`ellipse`](/docs/primitives/shape/ellipse) |
| a card, a button, a pill | [`roundedRect`](/docs/primitives/shape/roundedrect) |
| a triangle, a hexagon, any regular polygon | [`polygon`](/docs/primitives/shape/polygon) |
| a star or a flower | [`star`](/docs/primitives/shape/star), [`flower`](/docs/primitives/shape/flower) |
| a donut | [`ring`](/docs/primitives/shape/ring) |
| a pie slice or a gauge arc | [`arc`](/docs/primitives/shape/arc) with [`APERTURE_TO_HALF_ANGLE`](/docs/primitives/shape/aperture-to-half-angle) |
| a heart, a drop, a lens, a moon | [`heart`](/docs/primitives/shape/heart), [`teardrop`](/docs/primitives/shape/teardrop), [`vesica`](/docs/primitives/shape/vesica), [`crescent`](/docs/primitives/shape/crescent) |
| a slanted or tapered box | [`parallelogram`](/docs/primitives/shape/parallelogram), [`trapezoid`](/docs/primitives/shape/trapezoid) |
| a plus sign | [`cross`](/docs/primitives/shape/cross) |
| rounded corners on a sharp shape | `mix` toward [`circle`](/docs/primitives/shape/circle) |

## Example

```ts
import {defineShader, shape, math} from 'shaders/std'

const {polygon, circle} = shape

// A regular polygon whose corners round off toward a circle.
export const Hexagon = defineShader({
  role: 'shape',
  name: 'Hexagon',
  description: 'Regular polygon with adjustable sides and corner rounding',
  shape: {
    distance: ({x, y}, u) =>
      math.mix(polygon(x, y, u('radius'), u('sides')), circle(x, y, u('radius')), u('rounding')),
    colorDescription: 'Fill color of the polygon',
    centerDescription: 'Center position of the polygon',
    bounds: {size: {width: 'radius', height: 'radius'}},
    shapeProps: {
      radius: {
        default: 0.4,
        description: 'Distance from the center to the middle of each side',
        ui: {type: 'range', min: 0, max: 1, step: 0.01, label: 'Radius', group: 'Shape'},
      },
      sides: {
        default: 6,
        description: 'Number of sides (3 = triangle, 4 = square, 6 = hexagon)',
        ui: {type: 'range', min: 3, max: 12, step: 1, label: 'Sides', group: 'Shape'},
      },
      rounding: {
        default: 0,
        description: 'Corner rounding: 0 is sharp, 1 becomes a circle',
        ui: {type: 'range', min: 0, max: 1, step: 0.01, label: 'Rounding', group: 'Shape'},
      },
    },
  },
})
```

## Words

- [`circle`](/docs/primitives/shape/circle) — A circle of a given radius.
- [`ellipse`](/docs/primitives/shape/ellipse) — An ellipse with separate horizontal and vertical radii.
- [`roundedRect`](/docs/primitives/shape/roundedrect) — A rectangle with rounded corners.
- [`polygon`](/docs/primitives/shape/polygon) — A regular polygon with any number of sides.
- [`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.
- [`heart`](/docs/primitives/shape/heart) — A heart, point down at rotation 0.
- [`ring`](/docs/primitives/shape/ring) — A ring: a circular band around a centre.
- [`arc`](/docs/primitives/shape/arc) — A pie wedge: a filled sector of a circle.
- [`APERTURE_TO_HALF_ANGLE`](/docs/primitives/shape/aperture-to-half-angle) — The factor that turns an opening angle in degrees into the half-angle `arc` takes.
- [`vesica`](/docs/primitives/shape/vesica) — A vesica: the lens where two equal circles overlap.
- [`crescent`](/docs/primitives/shape/crescent) — A crescent: a disc with a smaller disc bitten out of it.
- [`teardrop`](/docs/primitives/shape/teardrop) — A teardrop: a round bulb tapering to a sharp point, point up at rotation 0.
- [`cross`](/docs/primitives/shape/cross) — A plus-shaped cross with four equal arms.
- [`trapezoid`](/docs/primitives/shape/trapezoid) — A trapezoid: a four-sided shape with a flat top and bottom of different widths.
- [`parallelogram`](/docs/primitives/shape/parallelogram) — A parallelogram: a rectangle with its top edge slid sideways.