Color

Reference for the Color utilities, presets and functions for working with colors in Ursina (HSV, RGB, alpha, tints, random, conversion, brightness, inverse).

Color

Located in ursina/color.py

Overview

The color module provides:

  • A large set of named color presets (HSV‑ and RGB‑based)
  • Functions to create or convert colors (HSV, RGB, RGBA, hex)
  • Utilities for brightness, inversion, tinting and random color generation

Note: the top‑level color(...) constructor is deprecated in favor of hsv(...).

Preset Colors

NameDefinition
whitehsv(0,0,1)
smokehsv(0,0,0.96)
light_grayhsv(0,0,0.75)
grayhsv(0,0,0.5)
dark_grayhsv(0,0,0.25)
blackhsv(0,0,0)
redhsv(0,1,1)
yellowhsv(60,1,1)
limehsv(90,1,1)
greenhsv(120,1,1)
turquoisehsv(150,1,1)
cyanhsv(180,1,1)
azurehsv(210,1,1)
bluehsv(240,1,1)
violethsv(270,1,1)
magentahsv(300,1,1)
pinkhsv(330,1,1)
brownrgb32(165,42,42)
olivergb32(128,128,0)
peachrgb32(255,218,185)
goldrgb32(255,215,0)
salmonrgb32(250,128,114)
clearrgba(0,0,0,0)
white10rgba(1,1,1,0.10)
white33rgba(1,1,1,0.33)
white50rgba(1,1,1,0.50)
white66rgba(1,1,1,0.66)
black10rgba(0,0,0,0.10)
black33rgba(0,0,0,0.33)
black50rgba(0,0,0,0.50)
black66rgba(0,0,0,0.66)
black90rgba(0,0,0,0.90)
text, light_textsmoke
dark_texthsv(0,0,0.1)
text_colorlight_text

Functions

FunctionDescription
color(h,s,v,a=1)Deprecated alias for hsv(h,s,v,a).
hsv(h,s,v,a=1)Create an HSV‑based color.
rgba32(r,g,b,a=255)Create color from 0–255 RGBA components.
rgb32(r,g,b)Create opaque color from 0–255 RGB.
rgba(r,g,b,a)Create color from 0–1 RGBA floats.
rgb(r,g,b)Create opaque color from 0–1 RGB floats.
to_hsv(color)Convert any color to HSV tuple.
hex(value)Parse a hexadecimal color string ('#RRGGBB' or '#RRGGBBAA').
rgb_to_hex(r,g,b,a=1)Convert RGBA floats to hex string.
brightness(color)Return brightness (V component) of an HSV color.
inverse(color)Return the inverse (complement) of a color.
random_color()Generate a random HSV color with full saturation and value.
tint(color, amount=0.2)Lighten or darken by mixing toward white (amount>0) or black (<0).

Example Usage

from ursina import *
from ursina import Ursina, Entity, Button, Quad, grid_layout, color

app = Ursina()

# show all named presets
p = Entity(x=-2)
for key, c in color.colors.items():
    b = Button(parent=p, model=Quad(0), color=c, text=key)
    b.text_entity.scale *= 0.5
grid_layout(p.children, max_x=8)

# color utilities
print('blue brightness:', color.brightness(color.blue))
print('inverse of red:', color.inverse(color.red))
print('random HSV:', color.random_color())

# hex conversions
print('rgb_to_hex:', color.rgb_to_hex(*color.blue))
print('parse hex:', color.hex('#ffa500'))

app.run()