> For the complete documentation index, see [llms.txt](https://docs.autowall.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.autowall.fun/documentation/vars/color.md).

# Color

## <i class="fa-swatchbook">:swatchbook:</i> Color

Like `vector`, `color(...)` is a Lua-side table+metatable (defined in the prelude), fields `r`,`g`,`b`,`a` in **0..255**.

```lua
color(255, 120, 40)          -- RGB, alpha defaults to 255
color(255, 120, 40, 180)     -- RGBA
color("FF7828")              -- hex RGB, alpha defaults to 255
color("FF7828CC")            -- hex RGBA
```

```lua
local c = color(255, 100, 50, 200)

c.r, c.g, c.b, c.a         -- direct 0..255 fields

c:to_fraction()             -- r,g,b,a each divided by 255 (four return values)
c:unpack()                  -- r, g, b, a (0..255)
c:to_hex()                  -- "RRGGBBAA" string
c:to_int32()                -- packed uint32, ABGR-in-uint32 (r in the low byte)
c:as_fraction(1, 0.5, 0.25, 1)  -- set fields *from* 0..1 values, in place
c:as_int32(0xFFFFFFFF)          -- set fields from a packed int, in place

c:alpha_modulate(120)        -- new color, alpha scaled by 120/255
c:grayscale(1.0)             -- new color, desaturated by t (0..1, 1 = full gray)
c:lerp(color(0,0,0), 0.5)    -- new color, interpolated
tostring(c)                  -- "color(255, 100, 50, 200)"
```

### Passing colors to `render.*`

`render.*` functions accept **either**:

* a `color(...)` object (0..255 fields), **or**
* a plain array table like `{1, 1, 1, 1}` in **0..1** float range.

{% hint style="danger" %}
Both are auto-detected (a table with an `r` field is treated as a `color()`; otherwise it's read positionally as `{r,g,b,a}` in 0..1). Don't mix — passing `{255, 0, 0}` as a raw array is interpreted as 0..1 floats (i.e. fully saturated white-ish, not red), not 0..255. Use `color(255, 0, 0)` if you want 0..255 input.
{% endhint %}


---

# 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://docs.autowall.fun/documentation/vars/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.
