> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: color
description: RGBA color object constructor and methods
icon: palette
---

The `color` namespace provides an RGBA color object with constructors and methods for converting between color spaces, interpolating, and modulating values.

## clone

```lua
color_object:clone(): color
```

> Creates and returns a copy of the color object.

<Schema title="Returns">
  <SchemaField name="color" type="color">
    A copy of the color object.
  </SchemaField>
</Schema>

## init

> Overwrites the color's ranges. Returns itself.

<Tabs>
  <Tab title="RGBA">
    ```lua
    color_object:init(r: number, g: number, b: number, a: number): color
    ```

    <Info>
      **Available overloads (`RGBA`)**

      ```lua
      color() -> 255, 255, 255, 255
      color(200) -> 200, 200, 200, 255
      color(255, 160) -> 255, 255, 255, 160
      color(255, 195, 25) -> 255, 195, 25, 255
      color(255, 195, 25, 200) -> 255, 195, 25, 200
      ```
    </Info>

    <Schema title="Parameters">
      <SchemaField name="r" type="number">
        New R color range
      </SchemaField>

      <SchemaField name="g" type="number">
        New G color range
      </SchemaField>

      <SchemaField name="b" type="number">
        New B color range
      </SchemaField>

      <SchemaField name="a" type="number">
        New A color range
      </SchemaField>
    </Schema>

    <Schema title="Returns">
      <SchemaField name="color" type="color">
        The color object itself.
      </SchemaField>
    </Schema>
  </Tab>

  <Tab title="HEX">
    ```lua
    color_object:init(value: string): color
    ```

    <Info>
      **Available overloads (`HEX` -> `RGBA`)**

      ```lua
      color 'C8' -> 200, 200, 200, 255
      color 'FFA0' -> 255, 255, 255, 160
      color 'FFC319' -> 255, 195, 25, 255
      color 'AABBCCDD' -> 170, 187, 204, 221
      ```
    </Info>

    <Schema title="Parameters">
      <SchemaField name="value" type="string">
        HEX string value (Format: AABBCCDD including all available overloads)
      </SchemaField>
    </Schema>

    <Schema title="Returns">
      <SchemaField name="color" type="color">
        The color object itself.
      </SchemaField>
    </Schema>
  </Tab>
</Tabs>

## as\_fraction

```lua
color_object:as_fraction(r: number, g: number, b: number, a: number): color
```

> Overwrites the color's ranges using the fraction values. Returns itself.

<Schema title="Parameters">
  <SchemaField name="r" type="number">
    New R color range as a percentage in the range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="g" type="number">
    New G color range as a percentage in the range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="b" type="number">
    New B color range as a percentage in the range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="a" type="number">
    New A color range as a percentage in the range \[0.0, 1.0]
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The color object itself.
  </SchemaField>
</Schema>

## as\_int32

```lua
color_object:as_int32(value: number): color
```

> Overwrites the color's ranges converting the int32 value to RGBA values. Returns itself.

<Schema title="Parameters">
  <SchemaField name="value" type="number">
    int32 color value
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The color object itself.
  </SchemaField>
</Schema>

## as\_hsv

```lua
color_object:as_hsv(h: number, s: number, v: number, a: number): color
```

> Overwrites the color's ranges converting the HSV to RGBA values. Returns itself.

<Schema title="Parameters">
  <SchemaField name="h" type="number">
    Hue color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="s" type="number">
    Saturation color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="v" type="number">
    Value color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="a" type="number">
    Alpha color range \[0.0, 1.0]
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The color object itself.
  </SchemaField>
</Schema>

## as\_hsl

```lua
color_object:as_hsl(h: number, s: number, l: number, a: number): color
```

> Overwrites the color's ranges converting the HSL to RGBA values. Returns itself.

<Schema title="Parameters">
  <SchemaField name="h" type="number">
    Hue color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="s" type="number">
    Saturation color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="l" type="number">
    Lightness color range \[0.0, 1.0]
  </SchemaField>

  <SchemaField name="a" type="number">
    Alpha color range \[0.0, 1.0]
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The color object itself.
  </SchemaField>
</Schema>

## to\_fraction

```lua
color_object:to_fraction(): number, number, number, number
```

> Returns the r, g, b, and a ranges of the color as a percentage in the range of \[0.0, 1.0].

<Schema title="Returns">
  <SchemaField name="r" type="number">
    R range as a percentage in the range \[0.0, 1.0].
  </SchemaField>

  <SchemaField name="g" type="number">
    G range as a percentage in the range \[0.0, 1.0].
  </SchemaField>

  <SchemaField name="b" type="number">
    B range as a percentage in the range \[0.0, 1.0].
  </SchemaField>

  <SchemaField name="a" type="number">
    A range as a percentage in the range \[0.0, 1.0].
  </SchemaField>
</Schema>

## to\_hex

```lua
color_object:to_hex(): string
```

> Returns the HEX string representing the color.

<Schema title="Returns">
  <SchemaField name="string" type="string">
    The HEX string representing the color.
  </SchemaField>
</Schema>

## to\_int32

```lua
color_object:to_int32(): number
```

> Returns the int32 value representing the color.

<Schema title="Returns">
  <SchemaField name="number" type="number">
    The int32 value representing the color.
  </SchemaField>
</Schema>

## to\_hsv

```lua
color_object:to_hsv(): number, number, number
```

> Returns the HSV representation of the color.

<Schema title="Returns">
  <SchemaField name="h" type="number">
    Hue.
  </SchemaField>

  <SchemaField name="s" type="number">
    Saturation.
  </SchemaField>

  <SchemaField name="v" type="number">
    Value.
  </SchemaField>
</Schema>

## to\_hsl

```lua
color_object:to_hsl(): number, number, number
```

> Returns the HSL representation of the color.

<Schema title="Returns">
  <SchemaField name="h" type="number">
    Hue.
  </SchemaField>

  <SchemaField name="s" type="number">
    Saturation.
  </SchemaField>

  <SchemaField name="l" type="number">
    Lightness.
  </SchemaField>
</Schema>

## lerp

```lua
color_object:lerp(other: color, weight: number): color
```

> Returns the linearly interpolated color between two colors by the specified weight.

<Schema title="Parameters">
  <SchemaField name="other" type="color" required>
    The color to interpolate to
  </SchemaField>

  <SchemaField name="weight" type="number" required>
    A value between 0 and 1 that indicates the weight of other
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The linearly interpolated color.
  </SchemaField>
</Schema>

## grayscale

```lua
color_object:grayscale([ weight: number ]): color
```

> Returns the grayscaled color.

<Schema title="Parameters">
  <SchemaField name="weight" type="number">
    Optional. A value between 0 and 1 that indicates the weight of grayscale
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The grayscaled color.
  </SchemaField>
</Schema>

## alpha\_modulate

```lua
color_object:alpha_modulate(alpha: number): color
```

> Returns the current color with an overridden Alpha color range.

<Schema title="Parameters">
  <SchemaField name="alpha" type="number" required>
    Alpha color range \[0, 255]
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="color" type="color">
    The current color with an overridden Alpha color range.
  </SchemaField>
</Schema>

## unpack

```lua
color_object:unpack(): number, number, number, number
```

> Returns the r, g, b, and a values of the color. Note that these fields can be accessed by indexing r, g, b, and a.

<Schema title="Returns">
  <SchemaField name="r" type="number">
    The R value of the color.
  </SchemaField>

  <SchemaField name="g" type="number">
    The G value of the color.
  </SchemaField>

  <SchemaField name="b" type="number">
    The B value of the color.
  </SchemaField>

  <SchemaField name="a" type="number">
    The A value of the color.
  </SchemaField>
</Schema>
