# Shapes

> The five built-in shapes — `rect`, `ellipse`, `polygon`, `star` and `arc` — their sizes, corner radius, sides, inner radius, angles and the progress-ring pattern.

vidmake has five vector shapes. They are resolution independent, take any [paint](https://vidmake.app/docs/colors.md) as
`fill` or `stroke`, and accept every [common field](https://vidmake.app/docs/layers.md): position, anchor, rotation, scale,
opacity, shadow, filters and presets.

**Demo: rect, ellipse, polygon, star and arc: the five built-in shapes** (rendered video: https://vidmake.app/media/shapes-gallery.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "shapes", "description": "rect, ellipse, polygon, star and arc: the five built-in shapes",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "rect", "type": "rect", "x": 200, "y": 330, "width": 150, "height": 150, "cornerRadius": 6, "fill": "#161412",
        "enter": "pop" },
      { "id": "ellipse", "type": "ellipse", "x": 420, "y": 330, "width": 160, "height": 120, "fill": "#4a4640",
        "start": "0.1s", "enter": "pop" },
      { "id": "polygon", "type": "polygon", "sides": 6, "x": 640, "y": 330, "width": 160, "fill": "#e9e4d8",
        "stroke": "#161412", "strokeWidth": 2, "rotation": "=t * 30", "start": "0.2s", "enter": "pop" },
      { "id": "star", "type": "star", "sides": 5, "innerRadius": 0.45, "x": 860, "y": 330, "width": 170, "fill": "#c92a26",
        "rotation": "=-t * 30", "start": "0.3s", "enter": "pop" },
      { "id": "arc", "type": "arc", "x": 1080, "y": 330, "width": 150, "stroke": "#161412", "strokeWidth": 14,
        "startAngle": "=t * 90", "endAngle": "=t * 90 + 270", "start": "0.4s", "enter": "pop" },
      { "id": "label", "type": "text", "y": 500, "font": "JetBrains Mono", "fontSize": 20, "letterSpacing": 2.4,
        "uppercase": true, "fill": "#8a857a", "x": "=200 + i * 220", "repeat": { "count": 5, "delay": "0.1s" }, "enter": "fadeUp",
        "text": "${pick(i, ['rect', 'ellipse', 'polygon', 'star', 'arc'])}" }
    ]
  }]
}
```

| type | extra fields | default size |
|---|---|---|
| `rect` | `cornerRadius` | the full parent (when neither `width` nor `height` is set) |
| `ellipse` | | 100×100 |
| `polygon` | `sides` | 100×100 |
| `star` | `sides`, `innerRadius` | 100×100 |
| `arc` | `startAngle`, `endAngle`, `closed` | 100×100 |

For `ellipse`, `polygon`, `star` and `arc`, setting only `width` or only `height` makes the shape
square, so `"width": 80` is an 80 px circle. Set both for an oval or a stretched polygon.

## rect

A rectangle with optional rounded corners.

```json
{ "id": "card", "type": "rect", "width": 480, "height": 280, "cornerRadius": 6, "fill": "#fbf9f4",
  "stroke": "#161412", "strokeWidth": 2 }
```

With **neither** `width` nor `height`, a rect fills its parent, so `{ "type": "rect", "fill": "#f4f1ea" }`
as the first layer is a background (and as the first child of a [group](https://vidmake.app/docs/groups.md), the group's
background). If you set only one of the two, the other defaults to `100`, not to the parent size.

`cornerRadius` is in px, is animatable, and is clamped to half the shorter side; `"50%"` turns any rect
into a pill (or a circle, if it is square). Rects are also the workhorse for bars and progress bars:
anchor one end and animate `width`.

```json
{ "id": "progress", "type": "rect", "anchor": "left", "x": 100, "y": 650, "height": 12, "cornerRadius": 6,
  "width": { "from": 0, "to": 1080, "duration": "4s", "ease": "linear" }, "fill": "#c92a26" }
```

## ellipse

An ellipse inscribed in its box: `width` and `height` are the two diameters. Dots, avatars, glows and
spotlights are all ellipses.

```json
{ "id": "dot", "type": "ellipse", "width": 24, "fill": "#c92a26" }
```

## polygon

A regular polygon with `sides` corners (default `3`, minimum `3`), inscribed in the layer's box with
its first corner pointing straight up. `"sides": 6` is a hexagon, `"sides": 4` a diamond (rotate it 45°
for a square).

```json
{ "id": "hex", "type": "polygon", "sides": 6, "width": 160, "fill": "#4a4640", "rotation": "=t * 30" }
```

`sides` is a plain number and cannot animate.

## star

A star with `sides` points (default `5`) alternating between the outer edge of the box and an inner
radius.

| field | default | notes |
|---|---|---|
| `sides` | `5` | number of points (minimum 3), not animatable |
| `innerRadius` | `0.5` | the inner corners' distance from the center, as a fraction of the outer radius. Animatable |

A small `innerRadius` (0.2–0.4) makes spiky stars; values near 1 approach a polygon with `2 × sides`
corners, which is how you draw seals, badges and sunbursts.

**Demo: sides sets a star's points; innerRadius (animatable) sets how deep they cut** (rendered video: https://vidmake.app/media/shapes-star.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "star", "description": "sides sets a star's points; innerRadius (animatable) sets how deep they cut",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "star4", "type": "star", "sides": 4, "x": 320, "y": "45%", "width": 230, "fill": "#161412",
        "innerRadius": [[0, 0.3], ["2s", 0.8, "easeInOutSine"], ["4s", 0.3, "easeInOutSine"]], "rotation": "=t * 22.5" },
      { "id": "star5", "type": "star", "sides": 5, "x": 640, "y": "45%", "width": 230, "fill": "#161412",
        "innerRadius": [[0, 0.3], ["2s", 0.8, "easeInOutSine"], ["4s", 0.3, "easeInOutSine"]], "rotation": "=t * 18" },
      { "id": "star12", "type": "star", "sides": 12, "x": 960, "y": "45%", "width": 230, "fill": "#161412",
        "innerRadius": [[0, 0.3], ["2s", 0.8, "easeInOutSine"], ["4s", 0.3, "easeInOutSine"]], "rotation": "=t * 7.5" },
      { "id": "sides", "type": "text", "y": "72%", "font": "JetBrains Mono", "fontSize": 20, "letterSpacing": 2.4,
        "uppercase": true, "fill": "#8a857a", "x": "=320 + i * 320", "repeat": 3, "text": "sides: ${pick(i, [4, 5, 12])}" },
      { "id": "inner", "type": "text", "y": "86%", "font": "JetBrains Mono", "fontSize": 28, "fill": "#c92a26",
        "text": "innerRadius: ${0.55 - 0.25 * cos(t * pi / 2):2}" }
    ]
  }]
}
```

## arc

An elliptical arc inside the layer's box, drawn as a **stroke**.

| field | default | notes |
|---|---|---|
| `startAngle` | `0` | degrees, 0 = 12 o'clock, clockwise. Animatable |
| `endAngle` | `360` | degrees, animatable. The arc always runs from the smaller to the larger angle |
| `closed` | `false` | `true` draws a filled pie slice (center to the arc and back) instead of a stroke |
| `strokeWidth` | `8` | thicker than other shapes' default, since an open arc is only a stroke |

An open arc draws its `stroke`; if you set only `fill`, that paint is used as the stroke. Ends are
round (`lineCap: "round"`); use `"lineCap": "butt"` for flat ends. With `closed: true` the arc is a
normal filled shape (white by default) that can also take a `stroke`.

```json
{ "id": "spinner", "type": "arc", "width": 120, "stroke": "#1f5fb0", "strokeWidth": 12,
  "startAngle": "=t * 360", "endAngle": "=t * 360 + 270" }
{ "id": "slice", "type": "arc", "closed": true, "width": 300, "startAngle": 0, "endAngle": 72, "fill": "#c92a26" }
```

### Progress ring

Animate `endAngle` from 0 to 360 (or to the fraction you need) over a dimmer full-circle track. A
`${...}` text in the middle can count along with the same easing:

**Demo: A progress ring: an arc whose endAngle animates from 0 to 360** (rendered video: https://vidmake.app/media/shapes-ring.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [{
    "id": "ring", "description": "A progress ring: an arc whose endAngle animates from 0 to 360",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "track", "type": "arc", "y": "46%", "width": 320, "stroke": "#e9e4d8", "strokeWidth": 22 },
      { "id": "ring", "type": "arc", "y": "46%", "width": 320, "strokeWidth": 22, "stroke": "#c92a26",
        "endAngle": { "from": 0, "to": 302, "start": "0.3s", "duration": "2.2s", "ease": "easeInOutCubic" } },
      { "id": "pct", "type": "text", "y": "46%", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 112,
        "letterSpacing": -5, "fill": "#161412", "text": "${round(84 * easeInOutCubic(clamp((t - 0.3) / 2.2, 0, 1)))}%" },
      { "id": "caption", "type": "text", "y": "82%", "font": "JetBrains Mono", "fontSize": 20, "letterSpacing": 2.4, "uppercase": true,
        "fill": "#8a857a", "text": "Tasks complete", "start": "0.5s", "enter": "fadeUp" }
    ]
  }]
}
```

The stroke is centered on the circle, so a ring with `"width": 320` and `"strokeWidth": 22` spans
342 px on screen. For a pie chart, stack `closed` arcs whose start angle is the previous one's end.

## Common patterns

- **Background:** `{ "type": "rect", "fill": ... }` as the first layer, or a gradient paint for depth.
- **Outline only:** `"fill": null, "stroke": "#161412"`. Add `"dash": [12, 8]` for a dashed border.
- **Badges and seals:** a `star` with `"innerRadius": 0.85` and many `sides`.
- **Many shapes from one:** use [`repeat`](https://vidmake.app/docs/repeat.md) with `i` in expressions instead of copying a
  layer ten times.
- **Custom shapes:** anything else is a [`path`](https://vidmake.app/docs/paths.md) with SVG path data.

> [!TIP]
> A shape's box is what `inspect` reports and what the anchor refers to. The stroke and the shadow are
> drawn outside it, so leave a margin when a shape sits near the edge of a clipped group.
