# Color

### HSL Functions

#### hsl n1 n2 n3 shape

Returns `shape` with its color set to `n1` for hue, `n2` for saturation, and `n3` for lightness. `n1`, `n2`, and `n3` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
magenta_square = hsl 280 0.9 0.75 SQUARE
```

#### hsla n1 n2 n3 n4 shape

Returns `shape` with its color set to `n1` for hue, `n2` for saturation, `n3` for lightness, and `n4` for alpha. `n1`, `n2`, `n3` and `n4` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
transparent_magenta_square = hsla 280 0.9 0.75 0.5 SQUARE
```

#### h n shape

Returns `shape` with its hue set to `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Shorthand for the `hue` function.

Example:

```ocaml
white_cyan_square = h 180 SQUARE
white_cyan_square = hue 180 SQUARE
```

#### sat n shape

Returns `shape` with its saturation set to `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Shorthand for the `saturation` function.

Example:

```ocaml
white_gray_square = sat 0 SQUARE
white_gray_square = saturation 0 SQUARE
```

#### l n shape

Returns `shape` with its lightness set to `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Shorthand for the `lightness` function.

Example:

```ocaml
red_square = l 0.5 SQUARE
red_square = lightness 0.5 SQUARE
```

#### a n shape

Returns `shape` with its alpha set to `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Shorthand for the `alpha` function.

Example:

```ocaml
transparent_white_square = a 0.5 SQUARE
transparent_white_square = alpha 0.5 SQUARE
```

#### hshift n shape

Returns `shape` with its hue shifted by `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
white_cyan_square = hshift 180 SQUARE
```

#### satshift n shape

Returns `shape` with its saturation shifted by `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
white_gray_square = satshift -1 SQUARE
```

#### lshift n shape

Returns `shape` with its lightness shifted by `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
red_square = lshift -0.5 SQUARE
```

#### ashift n shape

Returns `shape` with its alpha shifted by `n`. `n` must be of the integer or float types and `shape` must be of the shape type.

Example:

```ocaml
transparent_white_square = ashift -0.5 SQUARE
```

### RGB Functions

#### hex color shape

Returns `shape` with its color set to `color`. `color` must be of the [hexadecimal type](../../syntax/primitives#hexadecimal) and `shape` must be of the shape type.

Example:

```ocaml
neon_green_square = hex 0x39ff14 SQUARE
blue_square = hex BLUE SQUARE
```

### Gradient Functions

#### solid shape

Returns `shape` with its gradient removed and its color set to a solid white.

Example:

```ocaml
white_square = solid (g (linear_grad -1 -1 1 1) SQUARE)
```

#### g grad shape

Returns `shape` with its gradient set to `grad`.

Shorthand for the `gradient` function.

Example:

```ocaml
gradient_square = g (linear_grad -1 -1 1 1) SQUARE
gradient_square = gradient (linear_grad -1 -1 1 1) SQUARE
```

#### linear\_grad start\_x start\_y end\_x end\_y

Returns a gradient object with a linear transition from (`start_x`, `start_y`) to (`end_x`, `end_y`). Accepts integer and float types.

Example:

```ocaml
linear_gradient = linear_grad 0.5 1 0.5 -1
```

#### radial\_grad start\_x start\_y end\_x end\_y radius

Returns a gradient object with a radial transition from (`start_x`, `start_y`) to (`end_x`, `end_y`) and a radius of `radius`. Accepts integer and float types.

Example:

```ocaml
radial_gradient = radial_grad 0 0 1 1 1
```

#### grad\_start x y grad

Returns `grad` with its start position set to (`x`, `y`). `x` and `y` must be of the integer or float types.

Example:

```ocaml
corner_to_corner = grad_start -1 -1 (linear_gradient 0 0 1 1)
```

#### grad\_end x y grad

Returns `grad` with its end position set to (`x`, `y`). `x` and `y` must be of the integer or float types.

Example:

```ocaml
corner_to_corner = grad_end 1 1 (linear_gradient -1 -1 0 0)
```

#### to\_linear\_grad grad

Converts `grad` to a linear gradient.

Example:

```ocaml
linear_gradient = to_linear_grad (radial_grad 0.5 1 0.5 -1 1)
```

#### grad\_radius radius grad

Returns `grad` with its radius set to `radius`, converting it to a radial gradient if necessary. `radius` must be of the integer or float types.

Example:

```ocaml
linear_gradient = to_linear_grad (radial_grad 0.5 1 0.5 -1 1)
```

#### grad\_stop\_hsl pos n1 n2 n3 grad

Returns `grad` with its color at position `pos` set to `n1` for hue, `n2` for saturation, and `n3` for lightness. `pos`, `n1`, `n2`, and `n3` must be of the integer or float types.

Example:

```ocaml
red_to_blue =
    grad_stop_hsl 0 0 1 0.5 (
    grad_stop_hsl 1 210 1 0.5 (
    linear_grad 0.5 1 0.5 -1))
```

#### grad\_stop\_hsla pos n1 n2 n3 n4 grad

Returns `grad` with its color at position `pos` set to `n1` for hue, `n2` for saturation, `n3` for lightness, and `n4` for alpha. `pos`, `n1`, `n2`, `n3`, and `n4` must be of the integer or float types.

Example:

```ocaml
red_to_faded_blue =
    grad_stop_hsl 0 0 1 0.5 (
    grad_stop_hsla 1 210 1 0.5 0.5 (
    linear_grad 0.5 1 0.5 -1))
```

#### grad\_stop\_hex pos color grad

Returns `grad` with its color at position `pos` set to `n1` for hue, `n2` for saturation, and `n3` for lightness. `pos`, `n1`, `n2`, and `n3` must be of the integer or float types.

Example:

```ocaml
red_to_blue =
    grad_stop_hex 0 0xf00 (
    grad_stop_hex 1 0x00f (
    linear_grad 0.5 1 0.5 -1))
```

#### grad\_spread\_mode sm grad

Returns `grad` with its spread mode set the `sm`.

Refer to [Spread Mode](../../syntax/primitives#spread-mode) for a full list of possible spread modes.

Example:

```ocaml
reflected = grad_spread_mode SPREAD_MODE_REFLECT (linear_grad -1 -1 0 0)
```
