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

# color

Cores RGBA.

Cores têm os campos `r`, `g`, `b` e `a`, de 0 a 255. `a` é a opacidade: 255 é sólido e 0 é invisível.

```lua
local orange = color(255, 140, 40)        -- a = 255
local shadow = color(0, 0, 0, 160)
local blue   = color("#3C78FF")           -- or color.hex("#3C78FF")
local faded  = orange:alpha(80)           -- same color, alpha 80
```

## Criar

| Função                          |                                                                                |
| ------------------------------- | ------------------------------------------------------------------------------ |
| `color(r, g, b, [a=255])`       | Cor a partir dos valores. Sem argumentos, branco.                              |
| `color(hex)` / `color.hex(hex)` | De um texto `"#RRGGBB"` ou `"#RRGGBBAA"`; o `#` é opcional                     |
| `color.hsv(h, s, v, [a=255])`   | Matiz `h` de 0 a 360, saturação `s` e brilho `v` de 0 a 1. Bom para arco-íris. |
| `color.is(value)`               | `true` se `value` é uma `color`                                                |

## Métodos

| Método             | Devolve                                   |
| ------------------ | ----------------------------------------- |
| `c:alpha(a)`       | Cópia com outra opacidade                 |
| `c:lerp(other, t)` | Mistura: `t = 0` é `c`, `t = 1` é `other` |
| `c:unpack()`       | `r, g, b, a`                              |
| `c:to_hex()`       | Texto `"#RRGGBBAA"`                       |
| `tostring(c)`      | `"color(255, 140, 40, 255)"`              |
| `c1 == c2`         | `true` se todos os campos forem iguais    |

```lua
-- health bar from red to green
local health = player.health / 100
local bar = color(255, 80, 80):lerp(color(80, 220, 120), health)

-- rainbow that cycles every 4 seconds
local rainbow = color.hsv(globals.realtime() * 90, 0.8, 1)
```

## Onde uma cor é esperada

Funções como `render.*`, `ui.toggle`, `ui.color` e `menu.set` aceitam uma `color` ou uma tabela simples:

```lua
render.line(0, 0, 100, 100, { 255, 0, 0 })                 -- array
render.line(0, 0, 100, 100, { r = 255, g = 0, b = 0, a = 128 })
```

Campos que faltam valem 255.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.perfectcs2.com/documentacao/tipos/color.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
