DMX system
Control DMX lighting hardware connected to player consoles.
Overview
Cosmos supports DMX512 lighting controllers connected to client PCs. The DMX module sends channel commands to clients to drive RGB lights, blinking effects, and animated behaviors synchronized with in-game events.
Each DMX channel maps to a light or group of lights. Channels 0–2 are conventionally Red, Green, Blue for RGB strips. Use dmx_set_color to drive all three channels from a single hex color string, or dmx_set_channel for per-channel control.
dmx_run_for_ship iterates every client connected to a player ship and calls your function once per client — use this to synchronize a whole bridge's lighting.
Quick example
== red_alert ==
dmx_run_for_ship(ship_id, lambda c: dmx_set_color(c, "#ff0000", 2, 10))
->END
== all_clear ==
dmx_run_for_ship(ship_id, lambda c: dmx_set_color(c, "#00ff00", 1, 0))
->END
from sbs_utils.procedural.dmx import dmx_run_for_ship, dmx_set_color, dmx_set_channel
dmx_run_for_ship(ship_id, lambda c: dmx_set_color(c, "#ff0000", 2, 10))
dmx_set_color(client_id, "#00ff00", 1, 0)
dmx_set_channel(client_id, 0, 3, speed=5, low=0, high=200) # channel 0, PULSE
DMX behavior values
| Value | Behavior |
|---|---|
| 0 | OFF |
| 1 | ON (solid) |
| 2 | BLINK |
| 3 | PULSE |
| 4 | RAMP UP |
| 5 | RAMP DOWN |
| 6 | RANDOM |
API
dmx_run_for_ship(player_ship, dmx_function)
Call a DMX function for every client connected to a player ship.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
player_ship
|
int | Agent
|
The player ship agent or ID. |
required |
dmx_function
|
callable
|
A callable that accepts a single |
required |
dmx_set_channel(client, dmx_channel, dmx_behavior, speed=0, low=0, high=255)
Set a single DMX channel's behavior and intensity range for a client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
int
|
The client ID. |
required |
dmx_channel
|
int
|
Channel number 0–255. Typically 0 = Red, 1 = Green, 2 = Blue. |
required |
dmx_behavior
|
int
|
Channel behavior (0 = OFF, 1 = ON, 2 = BLINK, 3 = PULSE, 4 = RAMPUP, 5 = RAMPDN, 6 = RANDOM). |
required |
speed
|
int
|
Blink/pulse speed. Defaults to 0. |
0
|
low
|
int
|
Minimum intensity 0–255. Defaults to 0. |
0
|
high
|
int
|
Maximum intensity 0–255. Defaults to 255. |
255
|
dmx_set_color(client, color, dmx_behavior, speed)
Set DMX channels 0–2 (R/G/B) from a hex color string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
int
|
The client ID. |
required |
color
|
str
|
Hex color string, e.g. |
required |
dmx_behavior
|
int
|
Channel behavior (0 = OFF, 1 = ON, 2 = BLINK, 3 = PULSE, 4 = RAMPUP, 5 = RAMPDN, 6 = RANDOM). |
required |
speed
|
int
|
Blink/pulse speed; |
required |
hex_to_rgb(hex_color)
Convert a hex color string to an (r, g, b) integer tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_color
|
str
|
Hex color code, with or without a leading |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
tuple[int, int, int]: |