Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
color.qh File Reference
#include "string.qh"
Include dependency graph for color.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define COLORED_NAME(this)
#define colormapPaletteColor(c, isPants)

Functions

ERASEABLE vector colormapPaletteColor_ (int c, bool isPants, float t)
ERASEABLE vector hsl_to_rgb (vector hsl)
ERASEABLE vector hsv_to_rgb (vector hsv)
ERASEABLE vector hue_mi_ma_to_rgb (float hue, float mi, float ma)
ERASEABLE float rgb_mi_ma_to_hue (vector rgb, float mi, float ma)
ERASEABLE string rgb_to_hexcolor (vector rgb)
ERASEABLE vector rgb_to_hsl (vector rgb)
ERASEABLE vector rgb_to_hsv (vector rgb)

Macro Definition Documentation

◆ COLORED_NAME

#define COLORED_NAME ( this)
Value:
strcat(rgb_to_hexcolor(this.m_color), (this.message ? this.message : this.m_name), "^7")
string message
Definition powerups.qc:19
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
string m_name
Definition scores.qh:142
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

Definition at line 195 of file color.qh.

◆ colormapPaletteColor

Function Documentation

◆ colormapPaletteColor_()

ERASEABLE vector colormapPaletteColor_ ( int c,
bool isPants,
float t )

Definition at line 7 of file color.qh.

8{
9 // these colors are defined in gfx/colormap_palette.pl
10 // to generate them run: perl gfx/colormap_palette.pl > gfx/colormap_palette.lmp
11 // it will save them to gfx/colormap_palette.lmp (in the lmp format)
12 // and prints the cases of the following switch so they can be copy-pasted here
13
14 switch (c)
15 {
16 // generated by gfx/colormap_palette.pl
17 case 0: return '1.000000 1.000000 1.000000';
18 case 1: return '1.000000 0.333333 0.000000';
19 case 2: return '0.000000 1.000000 0.501961';
20 case 3: return '0.000000 1.000000 0.000000';
21 case 4: return '1.000000 0.000000 0.000000';
22 case 5: return '0.000000 0.666667 1.000000';
23 case 6: return '0.000000 1.000000 1.000000';
24 case 7: return '0.501961 1.000000 0.000000';
25 case 8: return '0.501961 0.000000 1.000000';
26 case 9: return '1.000000 0.000000 1.000000';
27 case 10: return '1.000000 0.000000 0.501961';
28 case 11: return '0.000000 0.000000 1.000000';
29 case 12: return '1.000000 1.000000 0.000000';
30 case 13: return '0.000000 0.333333 1.000000';
31 case 14: return '1.000000 0.666667 0.000000';
32 case 15:
33 if (isPants)
34 return '1 0 0' * (0.502 + 0.498 * sin(t / M_E + 0))
35 + '0 1 0' * (0.502 + 0.498 * sin(t / M_E + M_PI * 2 / 3))
36 + '0 0 1' * (0.502 + 0.498 * sin(t / M_E + M_PI * 4 / 3));
37 else
38 return '1 0 0' * (0.502 + 0.498 * sin(t / M_PI + M_PI * 5 / 3))
39 + '0 1 0' * (0.502 + 0.498 * sin(t / M_PI + M_PI))
40 + '0 0 1' * (0.502 + 0.498 * sin(t / M_PI + M_PI * 1 / 3));
41 default: return '0.000 0.000 0.000';
42 }
43}
const float M_E
Definition mathlib.qh:102
#define M_PI
Definition mathlib.qh:108
float sin(float f)

References M_E, M_PI, sin(), and vector.

◆ hsl_to_rgb()

ERASEABLE vector hsl_to_rgb ( vector hsl)

Definition at line 167 of file color.qh.

168{
169 float mi, ma, maminusmi;
170
171 if (hsl.z <= 0.5) maminusmi = hsl.y * 2 * hsl.z;
172 else maminusmi = hsl.y * (2 - 2 * hsl.z);
173
174 // hsl_z = 0.5 * mi + 0.5 * ma
175 // maminusmi = - mi + ma
176 mi = hsl.z - 0.5 * maminusmi;
177 ma = hsl.z + 0.5 * maminusmi;
178
179 return hue_mi_ma_to_rgb(hsl.x, mi, ma);
180}
ERASEABLE vector hue_mi_ma_to_rgb(float hue, float mi, float ma)
Definition color.qh:68

References hue_mi_ma_to_rgb(), and vector.

Referenced by GenericCommand(), and hslimage_color().

◆ hsv_to_rgb()

ERASEABLE vector hsv_to_rgb ( vector hsv)

Definition at line 141 of file color.qh.

142{
143 return hue_mi_ma_to_rgb(hsv.x, hsv.z * (1 - hsv.y), hsv.z);
144}

References hue_mi_ma_to_rgb(), and vector.

Referenced by Draw_WaypointSprite(), and DrawAmmoNades().

◆ hue_mi_ma_to_rgb()

ERASEABLE vector hue_mi_ma_to_rgb ( float hue,
float mi,
float ma )

Definition at line 68 of file color.qh.

69{
70 vector rgb;
71
72 hue -= 6 * floor(hue / 6);
73
74 // else if(ma == rgb_x)
75 // hue = 60 * (rgb_y - rgb_z) / (ma - mi);
76 if (hue <= 1)
77 {
78 rgb.x = ma;
79 rgb.y = hue * (ma - mi) + mi;
80 rgb.z = mi;
81 }
82 // else if(ma == rgb_y)
83 // hue = 60 * (rgb_z - rgb_x) / (ma - mi) + 120;
84 else if (hue <= 2)
85 {
86 rgb.x = (2 - hue) * (ma - mi) + mi;
87 rgb.y = ma;
88 rgb.z = mi;
89 }
90 else if (hue <= 3)
91 {
92 rgb.x = mi;
93 rgb.y = ma;
94 rgb.z = (hue - 2) * (ma - mi) + mi;
95 }
96 // else // if(ma == rgb_z)
97 // hue = 60 * (rgb_x - rgb_y) / (ma - mi) + 240;
98 else if (hue <= 4)
99 {
100 rgb.x = mi;
101 rgb.y = (4 - hue) * (ma - mi) + mi;
102 rgb.z = ma;
103 }
104 else if (hue <= 5)
105 {
106 rgb.x = (hue - 4) * (ma - mi) + mi;
107 rgb.y = mi;
108 rgb.z = ma;
109 }
110 // else if(ma == rgb_x)
111 // hue = 60 * (rgb_y - rgb_z) / (ma - mi);
112 else // if(hue <= 6)
113 {
114 rgb.x = ma;
115 rgb.y = mi;
116 rgb.z = (6 - hue) * (ma - mi) + mi;
117 }
118
119 return rgb;
120}
float floor(float f)
vector
Definition self.qh:92

References floor(), and vector.

Referenced by hsl_to_rgb(), and hsv_to_rgb().

◆ rgb_mi_ma_to_hue()

ERASEABLE float rgb_mi_ma_to_hue ( vector rgb,
float mi,
float ma )

Definition at line 46 of file color.qh.

47{
48 if (mi == ma)
49 {
50 return 0;
51 }
52 else if (ma == rgb.x)
53 {
54 if (rgb.y >= rgb.z) return (rgb.y - rgb.z) / (ma - mi);
55 else return (rgb.y - rgb.z) / (ma - mi) + 6;
56 }
57 else if (ma == rgb.y)
58 {
59 return (rgb.z - rgb.x) / (ma - mi) + 2;
60 }
61 else // if(ma == rgb_z)
62 {
63 return (rgb.x - rgb.y) / (ma - mi) + 4;
64 }
65}

References vector.

Referenced by rgb_to_hsl(), and rgb_to_hsv().

◆ rgb_to_hexcolor()

ERASEABLE string rgb_to_hexcolor ( vector rgb)

Definition at line 183 of file color.qh.

184{
185 return strcat("^x",
186 DEC_TO_HEXDIGIT(floor(bound(0, rgb.x, 1) * 15 + 0.5)),
187 DEC_TO_HEXDIGIT(floor(bound(0, rgb.y, 1) * 15 + 0.5)),
188 DEC_TO_HEXDIGIT(floor(bound(0, rgb.z, 1) * 15 + 0.5))
189 );
190}
float bound(float min, float value, float max)
#define DEC_TO_HEXDIGIT(d)
Definition string.qh:572

References bound(), DEC_TO_HEXDIGIT, floor(), strcat(), and vector.

Referenced by BUFF_NAME(), GameTypeVote_DrawGameTypeItem(), GenericCommand(), getDemos_for_ext(), getScreenshots_for_ext(), gettooltip(), HUD_Checkpoints(), HUD_RaceTimer(), MapVote_DrawMapItem(), and XonoticColorpicker_mouseDrag().

◆ rgb_to_hsl()

ERASEABLE vector rgb_to_hsl ( vector rgb)

Definition at line 147 of file color.qh.

148{
149 float mi, ma;
150 vector hsl;
151
152 mi = min(rgb.x, rgb.y, rgb.z);
153 ma = max(rgb.x, rgb.y, rgb.z);
154
155 hsl.x = rgb_mi_ma_to_hue(rgb, mi, ma);
156
157 hsl.z = 0.5 * (mi + ma);
158 if (mi == ma) hsl.y = 0;
159 else if (hsl.z <= 0.5) hsl.y = (ma - mi) / (2 * hsl.z);
160 else // if(hsl_z > 0.5)
161 hsl.y = (ma - mi) / (2 - 2 * hsl.z);
162
163 return hsl;
164}
ERASEABLE float rgb_mi_ma_to_hue(vector rgb, float mi, float ma)
Definition color.qh:46
float min(float f,...)
float max(float f,...)

References max(), min(), rgb_mi_ma_to_hue(), and vector.

Referenced by color_hslimage().

◆ rgb_to_hsv()

ERASEABLE vector rgb_to_hsv ( vector rgb)

Definition at line 123 of file color.qh.

124{
125 float mi, ma;
126 vector hsv;
127
128 mi = min(rgb.x, rgb.y, rgb.z);
129 ma = max(rgb.x, rgb.y, rgb.z);
130
131 hsv.x = rgb_mi_ma_to_hue(rgb, mi, ma);
132 hsv.z = ma;
133
134 if (ma == 0) hsv.y = 0;
135 else hsv.y = 1 - mi / ma;
136
137 return hsv;
138}

References max(), min(), rgb_mi_ma_to_hue(), and vector.

Referenced by Draw_WaypointSprite().