> For the complete documentation index, see [llms.txt](https://lua2.axeprimecs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lua2.axeprimecs.com/instances-and-types/types/color.md).

# color

An **RGBA color** type with 0–255 range per channel.

***

## Constructors

| Constructor          | Description                                          |
| -------------------- | ---------------------------------------------------- |
| `color()`            | Default color                                        |
| `color(r, g, b)`     | RGB, alpha = 255                                     |
| `color(r, g, b, a)`  | Full RGBA                                            |
| `color("#rrggbbaa")` | Hex string (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`) |

***

## Fields

| Field | Type    |
| ----- | ------- |
| `r`   | `float` |
| `g`   | `float` |
| `b`   | `float` |
| `a`   | `float` |

***

## Static

| Static                                                    | Returns | Description                                 |
| --------------------------------------------------------- | ------- | ------------------------------------------- |
| `color.from_hex(hex)`                                     | `color` | Create from hex integer (e.g. `0xFF0000FF`) |
| `color.lerp(a, b, t)`                                     | `color` | Linearly interpolate between two colors     |
| `color.interpolate(a, b, t)`                              | `color` | Alias for `lerp`                            |
| `color.white()` / `color.black()`                         | `color` | Opaque white / black                        |
| `color.white_transparent()` / `color.black_transparent()` | `color` | Transparent white / black                   |
| `color.percent(p, a?)`                                    | `color` | Red→green gradient by percent (0..1)        |
| `color.gray(b, a?)`                                       | `color` | Black→white by percent (0..1)               |

***

## Methods

| Method                                                | Returns         | Description                               |
| ----------------------------------------------------- | --------------- | ----------------------------------------- |
| `with_alpha(alpha)`                                   | `color`         | Copy with modified alpha (0..255)         |
| `set_r(v)` / `set_g(v)` / `set_b(v)` / `set_a(v)`     | `color`         | Copy with one channel set (0..1)          |
| `get_r()` / `get_g()` / `get_b()` / `get_a()`         | `int`           | Channel value (0..255)                    |
| `mod_a(v)`                                            | `color`         | Multiply alpha (float 0..1 or int 0..255) |
| `darken(v)` / `lighten(v)`                            | `color`         | Darken / lighten by amount (0..1)         |
| `get_hue()` / `get_saturation()` / `get_brightness()` | `int` / `float` | Hue (0..359) / saturation / brightness    |
| `from_hsv(h, s, v, a?)`                               | `color`         | Construct from HSV                        |
| `to_rgba()` / `to_argb()` / `to_bgra()` / `to_abgr()` | `int`           | Packed integer representation             |

***

## ➕ Operators

Supports: `==`, `tostring`

***

## 💡 Example

```lua
local red = color(255, 0, 0)
local blue = color(0, 0, 255)
local purple = color.lerp(red, blue, 0.5)
local transparent_red = red:with_alpha(128)
local gold = color.from_hex(0xFFD700FF)
local hexed = color("#ff0000")
local dim = red:mod_a(0.5)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://lua2.axeprimecs.com/instances-and-types/types/color.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
