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

---
title: Color
icon: paint-bucket
---

# <ApiPageIcon icon="paint-bucket" />Color

<ApiExposes data="[{&#x22;k&#x22;:&#x22;CDATA&#x22;,&#x22;c&#x22;:&#x22;method&#x22;,&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;h&#x22;:&#x22;#color-1&#x22;},{&#x22;k&#x22;:&#x22;CTYPE&#x22;,&#x22;c&#x22;:&#x22;ctor&#x22;,&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;h&#x22;:&#x22;#color-2&#x22;}]" />

<Heading level={2} id="color-1">
  Color

  <ApiTag label="cdata" href="/cs2/api_reference/tutorials/ffi-crash-course#ctype-and-cdata" title="cdata<struct Color>" />
</Heading>

<ApiSymbol inherits="[{&#x22;n&#x22;:&#x22;Color&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-2&#x22;}]" />

A colour with red, green, blue and alpha channels. Each channel is a byte from 0 to 255.

`Color(r, g, b)` creates a colour that is fully visible, because an alpha that is not given
is set to 255. A red, green or blue channel that is not given is set to 0.

The `==` operator compares all four channels and returns `false` when the other value is
not a `Color`.

<ApiMembers>
  <ApiMember kind="prop" name="Color.a" summary="The alpha channel, from 0 to 255. 0 is fully transparent and 255 is fully visible." ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" />

  <ApiMember kind="prop" name="Color.b" summary="The blue channel, from 0 to 255." ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" />

  <ApiMember kind="prop" name="Color.g" summary="The green channel, from 0 to 255." ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" />

  <ApiMember kind="prop" name="Color.r" summary="The red channel, from 0 to 255." ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" />
</ApiMembers>

<Heading level={2} id="color-2">
  Color

  <ApiTag label="ctype · callable" href="/cs2/api_reference/tutorials/ffi-crash-course#ctype-and-cdata" title="ctype<struct Color>" />
</Heading>

Call `Color(r, g, b, a)` to create a colour. Call `Color(other)` to make a copy of another
colour.

<ApiMembers>
  <ApiMember kind="ctor" name="Color(r, g, b, a)" summary="The alpha is 255 if it is not given." syntax="Color(r?, g?, b?, a?)" mm="__call" sig="[{&#x22;s&#x22;:&#x22;Color&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;r&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;g&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;b&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;a&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;r&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;g&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;b&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;a&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true}]" />

  <ApiMember kind="ctor" name="Color(self)" syntax="Color(self)" mm="__call" sig="[{&#x22;s&#x22;:&#x22;Color&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;self&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;self&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]}]" />

  <ApiMember kind="fn" name="Color.Unpack" summary="Returns the red, green, blue and alpha channels of the colour." args="col" sig="[{&#x22;s&#x22;:&#x22;Color.Unpack&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;col&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;col&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}],&#x22;d&#x22;:&#x22;The colour to unpack.&#x22;}]" returns="[{&#x22;n&#x22;:&#x22;r&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;g&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;b&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;a&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]" nodiscard />

  <ApiMember kind="fn" name="Color.Lerp" summary="Returns a new colour between two colours. This is linear interpolation. Each channel of the result is rounded to the nearest whole number and clamped to the range from 0 to 255." args="a, b, t" sig="[{&#x22;s&#x22;:&#x22;Color.Lerp&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;a&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;b&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;t&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;number&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#number&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;a&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}],&#x22;d&#x22;:&#x22;The start colour.&#x22;},{&#x22;n&#x22;:&#x22;b&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}],&#x22;d&#x22;:&#x22;The end colour.&#x22;},{&#x22;n&#x22;:&#x22;t&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;number&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#number&#x22;}],&#x22;d&#x22;:&#x22;The interpolation factor. 0 returns `a` and 1 returns `b`.&#x22;}]" nodiscard />

  <ApiMember kind="fn" name="Color.Hex" summary="Returns the colour as a hex string in the format `RRGGBBAA`, with upper case letters. For example, `Color(255, 128, 0)` returns `&#x22;FF8000FF&#x22;`." args="col" sig="[{&#x22;s&#x22;:&#x22;Color.Hex&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;col&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;col&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;Color&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/mathlib/color#color-1&#x22;}],&#x22;d&#x22;:&#x22;The colour to format.&#x22;}]" nodiscard />
</ApiMembers>
