# color

## Example available!

{% content-ref url="../../useful-information/script-examples/color" %}
[color](https://docs-csgo.neverlose.cc/useful-information/script-examples/color)
{% endcontent-ref %}

## Functions:

### :clone

`color_object:clone():` <mark style="color:purple;">`color`</mark>

Creates and returns a copy of the color object.

### :init

{% tabs %}
{% tab title="RGBA" %}
`color_object:init(r: number, g: number, b: number, a: number):` <mark style="color:purple;">`color`</mark>

> 📌 Available overloads (`RGBA`):\
> color() -> `255`, `255`, `255`, `255`\
> color(<mark style="color:blue;">`200`</mark>) -> <mark style="color:blue;">`200`</mark>, <mark style="color:blue;">`200`</mark>, <mark style="color:blue;">`200`</mark>, `255`\
> color(<mark style="color:blue;">`255`</mark>, <mark style="color:yellow;">`160`</mark>) -> <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`255`</mark>, <mark style="color:yellow;">`160`</mark>\
> color(<mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`195`</mark>, <mark style="color:blue;">`25`</mark>) -> <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`195`</mark>, <mark style="color:blue;">`25`</mark>, `255`\
> color(<mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`195`</mark>, <mark style="color:blue;">`25`</mark>, <mark style="color:blue;">`200`</mark>) -> <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`195`</mark>, <mark style="color:blue;">`25`</mark>, <mark style="color:blue;">`200`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>r</strong></td><td><strong><code>number</code></strong></td><td>New R color range</td></tr><tr><td><strong>g</strong></td><td><strong><code>number</code></strong></td><td>New G color range</td></tr><tr><td><strong>b</strong></td><td><strong><code>number</code></strong></td><td>New B color range</td></tr><tr><td><strong>a</strong></td><td><strong><code>number</code></strong></td><td>New A color range</td></tr></tbody></table>
{% endtab %}

{% tab title="HEX" %}
`color_object:init(value: string):` <mark style="color:purple;">`color`</mark>

> 📌 Available overloads (`HEX` -> `RGBA`):\
> color '<mark style="color:blue;">`C8`</mark>' -> <mark style="color:blue;">`200`</mark>, <mark style="color:blue;">`200`</mark>, <mark style="color:blue;">`200`</mark>, `255`\
> color '<mark style="color:blue;">`FF`</mark><mark style="color:yellow;">`A0`</mark>' -> <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`255`</mark>, <mark style="color:yellow;">`160`</mark>\
> color '<mark style="color:blue;">`FFC319`</mark>' -> <mark style="color:blue;">`255`</mark>, <mark style="color:blue;">`195`</mark>, <mark style="color:blue;">`25`</mark>, `255`\
> color '<mark style="color:blue;">`AABBCCDD`</mark>' -> <mark style="color:blue;">`170`</mark>, <mark style="color:blue;">`187`</mark>, <mark style="color:blue;">`204`</mark>, <mark style="color:blue;">`221`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>value</strong></td><td><strong><code>string</code></strong></td><td>HEX string value (Format: <mark style="color:blue;"><code>AABBCCDD</code></mark> including all available overloads)</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

Overwrites the color's ranges. Returns itself.

### :as\_fraction

`color_object:as_fraction(r: number, g: number, b: number, a: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>r</strong></td><td><strong><code>number</code></strong></td><td>New R color range as a percentage in the range [0.0, 1.0]</td></tr><tr><td><strong>g</strong></td><td><strong><code>number</code></strong></td><td>New G color range as a percentage in the range [0.0, 1.0]</td></tr><tr><td><strong>b</strong></td><td><strong><code>number</code></strong></td><td>New B color range as a percentage in the range [0.0, 1.0]</td></tr><tr><td><strong>a</strong></td><td><strong><code>number</code></strong></td><td>New A color range as a percentage in the range [0.0, 1.0]</td></tr></tbody></table>

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

### :as\_int32

`color_object:as_int32(value: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>value</strong></td><td><strong><code>number</code></strong></td><td>int32 color value</td></tr></tbody></table>

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

### :as\_hsv

`color_object:as_hsv(h: number, s: number, v: number, a: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>h</strong></td><td><strong><code>number</code></strong></td><td>Hue color range [0.0, 1.0]</td></tr><tr><td><strong>s</strong></td><td><strong><code>number</code></strong></td><td>Saturation color range [0.0, 1.0]</td></tr><tr><td><strong>v</strong></td><td><strong><code>number</code></strong></td><td>Value color range [0.0, 1.0]</td></tr><tr><td><strong>a</strong></td><td><strong><code>number</code></strong></td><td>Alpha color range [0.0, 1.0]</td></tr></tbody></table>

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

### :as\_hsl

`color_object:as_hsl(h: number, s: number, l: number, a: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>h</strong></td><td><strong><code>number</code></strong></td><td>Hue color range [0.0, 1.0]</td></tr><tr><td><strong>s</strong></td><td><strong><code>number</code></strong></td><td>Saturation color range [0.0, 1.0]</td></tr><tr><td><strong>l</strong></td><td><strong><code>number</code></strong></td><td>Lightness color range [0.0, 1.0]</td></tr><tr><td><strong>a</strong></td><td><strong><code>number</code></strong></td><td>Alpha color range [0.0, 1.0]</td></tr></tbody></table>

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

### :to\_fraction

`color_object:to_fraction():` <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>

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

### :to\_hex

`color_object:to_hex():` <mark style="color:purple;">`string`</mark>

Returns the HEX string representing the color.

### :to\_int32

`color_object:to_int32():` <mark style="color:purple;">`number`</mark>

Returns the int32 value representing the color.

### :to\_hsv

`color_object:to_hsv():` <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>

Returns the HSV representation of the color.

### :to\_hsl

`color_object:to_hsl():` <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>

Returns the HSL representation of the color.

### :lerp

`color_object:lerp(other: color, weight: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>color</code></strong></td><td>The color to interpolate to</td></tr><tr><td><strong>weight</strong></td><td><strong><code>number</code></strong></td><td>A value between 0 and 1 that indicates the weight of <strong>other</strong></td></tr></tbody></table>

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

### :grayscale

`color_object:grayscale([ weight: number ]):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>weight</strong></td><td><strong><code>number</code></strong></td><td>Optional. A value between 0 and 1 that indicates the weight of <strong>grayscale</strong></td></tr></tbody></table>

Returns the grayscaled color.

### :alpha\_modulate

`color_object:alpha_modulate(alpha: number):` <mark style="color:purple;">`color`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>alpha</strong></td><td><strong><code>number</code></strong></td><td>Alpha color range [0, 255]</td></tr></tbody></table>

Returns the current color with an overridden Alpha color range.

### :unpack

`color_object:unpack():` <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>

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.
