Allegro.cc - Online Community

Allegro.cc Forums » The Depot » Simple list of colors...

This thread is locked; no one can reply to it. rss feed Print
Simple list of colors...
Onewing
Member #6,152
August 2005
avatar

Hello all, this is something very, very simple. So simple, it's almost silly. However, I've been using it since I started using allegro (and wrote these files on 4/10/2005). All it is, is a simple list of colors defined to replace makecol calls. In most cases, you'd just use makecol(r,g,b), but sometimes you just want to write the color name. Perhaps it is tedious to look up the list, but after a while, I've grown so use to it, I often just say a color name and can expect it to be in the list. And of course, there's routines to break a color into its separate r,g,b components of which I have also written functions for, but they aren't optimized so I'm not relaying them here.

Also note, that I didn't write this list of colors. They come from the CMUgraphics Library and I've included a disclaimer at the bottom of the header file. Well, anywho, here they are (you could just include the following code in your own header/cpp files somewhere).

In a header file:

// Apparently my post is too big.  I've attached the header code w/disclaimer in a text file.

In a c/cpp file:

#SelectExpand
1 2const int SNOW = makecol(255, 250, 250); 3const int GHOSTWHITE = makecol(248, 248, 255); 4const int WHITESMOKE = makecol(245, 245, 245); 5const int GAINSBORO = makecol(220, 220, 220); 6const int FLORALWHITE = makecol(255, 250, 240); 7const int OLDLACE = makecol(253, 245, 230); 8const int LINEN = makecol(250, 240, 230); 9const int ANTIQUEWHITE = makecol(250, 235, 215); 10const int PAPAYAWHIP = makecol(255, 239, 213); 11const int BLANCHEDALMOND = makecol(255, 235, 205); 12const int BISQUE = makecol(255, 228, 196); 13const int PEACHPUFF = makecol(255, 218, 185); 14const int NAVAJOWHITE = makecol(255, 222, 173); 15const int MOCCASIN = makecol(255, 228, 181); 16const int CORNSILK = makecol(255, 248, 220); 17const int IVORY = makecol(255, 255, 240); 18const int LEMONCHIFFON = makecol(255, 250, 205); 19const int SEASHELL = makecol(255, 245, 238); 20const int HONEYDEW = makecol(240, 255, 240); 21const int MINTCREAM = makecol(245, 255, 250); 22const int AZURE = makecol(240, 255, 255); 23const int ALICEBLUE = makecol(240, 248, 255); 24const int LAVENDER = makecol(230, 230, 250); 25const int LAVENDERBLUSH = makecol(255, 240, 245); 26const int MISTYROSE = makecol(255, 228, 225); 27const int WHITE = makecol(255, 255, 255); 28const int BLACK = makecol(0, 0, 0); 29const int DARKSLATEGRAY = makecol(47, 79, 79); 30const int DARKSLATEGREY = makecol(47, 79, 79); 31const int DIMGRAY = makecol(105, 105, 105); 32const int DIMGREY = makecol(105, 105, 105); 33const int SLATEGRAY = makecol(112, 128, 144); 34const int SLATEGREY = makecol(112, 128, 144); 35const int LIGHTSLATEGRAY = makecol(119, 136, 153); 36const int LIGHTSLATEGREY = makecol(119, 136, 153); 37const int GRAY = makecol(60, 60, 60); 38const int GREY = makecol(190, 190, 190); 39const int LIGHTGREY = makecol(211, 211, 211); 40const int LIGHTGRAY = makecol(211, 211, 211); 41const int MIDNIGHTBLUE = makecol(25, 25, 112); 42const int NAVY = makecol(0, 0, 128); 43const int NAVYBLUE = makecol(0, 0, 128); 44const int CORNFLOWERBLUE = makecol(100, 149, 237); 45const int DARKSLATEBLUE = makecol(72, 61, 139); 46const int SLATEBLUE = makecol(106, 90, 205); 47const int MEDIUMSLATEBLUE = makecol(123, 104, 238); 48const int LIGHTSLATEBLUE = makecol(132, 112, 255); 49const int MEDIUMBLUE = makecol(0, 0, 205); 50const int ROYALBLUE = makecol(65, 105, 225); 51const int BLUE = makecol(0, 0, 255); 52const int DODGERBLUE = makecol(30, 144, 255); 53const int DEEPSKYBLUE = makecol(0, 191, 255); 54const int SKYBLUE = makecol(135, 206, 235); 55const int LIGHTSKYBLUE = makecol(135, 206, 250); 56const int STEELBLUE = makecol(70, 130, 180); 57const int LIGHTSTEELBLUE = makecol(176, 196, 222); 58const int LIGHTBLUE = makecol(173, 216, 230); 59const int POWDERBLUE = makecol(176, 224, 230); 60const int PALETURQUOISE = makecol(175, 238, 238); 61const int DARKTURQUOISE = makecol(0, 206, 209); 62const int MEDIUMTURQUOISE = makecol(72, 209, 204); 63const int TURQUOISE = makecol(64, 224, 208); 64const int CYAN = makecol(0, 255, 255); 65const int LIGHTCYAN = makecol(224, 255, 255); 66const int CADETBLUE = makecol(95, 158, 160); 67const int MEDIUMAQUAMARINE = makecol(102, 205, 170); 68const int AQUAMARINE = makecol(127, 255, 212); 69const int DARKGREEN = makecol(0, 100, 0); 70const int DARKOLIVEGREEN = makecol(85, 107, 47); 71const int DARKSEAGREEN = makecol(143, 188, 143); 72const int SEAGREEN = makecol(46, 139, 87); 73const int MEDIUMSEAGREEN = makecol(60, 179, 113); 74const int LIGHTSEAGREEN = makecol(32, 178, 170); 75const int PALEGREEN = makecol(152, 251, 152); 76const int SPRINGGREEN = makecol(0, 255, 127); 77const int LAWNGREEN = makecol(124, 252, 0); 78const int GREEN = makecol(0, 255, 0); 79const int CHARTREUSE = makecol(127, 255, 0); 80const int MEDIUMSPRINGGREEN = makecol(0, 250, 154); 81const int GREENYELLOW = makecol(173, 255, 47); 82const int LIMEGREEN = makecol(50, 205, 50); 83const int YELLOWGREEN = makecol(154, 205, 50); 84const int FORESTGREEN = makecol(34, 139, 34); 85const int OLIVEDRAB = makecol(107, 142, 35); 86const int DARKKHAKI = makecol(189, 183, 107); 87const int KHAKI = makecol(240, 230, 140); 88const int PALEGOLDENROD = makecol(238, 232, 170); 89const int LIGHTGOLDENRODYELLOW = makecol(250, 250, 210); 90const int LIGHTYELLOW = makecol(255, 255, 224); 91const int YELLOW = makecol(255, 255, 0); 92const int GOLD = makecol(255, 215, 0); 93const int LIGHTGOLDENROD = makecol(238, 221, 130); 94const int GOLDENROD = makecol(218, 165, 32); 95const int DARKGOLDENROD = makecol(184, 134, 11); 96const int ROSYBROWN = makecol(188, 143, 143); 97const int INDIAN = makecol(205, 92, 92); 98const int INDIANRED = makecol(205, 92, 92); 99const int SADDLEBROWN = makecol(139, 69, 19); 100const int SIENNA = makecol(160, 82, 45); 101const int PERU = makecol(205, 133, 63); 102const int BURLYWOOD = makecol(222, 184, 135); 103const int BEIGE = makecol(245, 245, 220); 104const int WHEAT = makecol(245, 222, 179); 105const int SANDYBROWN = makecol(244, 164, 96); 106const int TAN = makecol(210, 180, 140); 107const int CHOCOLATE = makecol(210, 105, 30); 108const int FIREBRICK = makecol(178, 34, 34); 109const int BROWN = makecol(165, 42, 42); 110const int DARKSALMON = makecol(233, 150, 122); 111const int SALMON = makecol(250, 128, 114); 112const int LIGHTSALMON = makecol(255, 160, 122); 113const int ORANGE = makecol(255, 165, 0); 114const int DARKORANGE = makecol(255, 140, 0); 115const int CORAL = makecol(255, 127, 80); 116const int LIGHTCORAL = makecol(240, 128, 128); 117const int TOMATO = makecol(255, 99, 71); 118const int ORANGERED = makecol(255, 69, 0); 119const int RED = makecol(200, 0, 0); 120const int HOTPINK = makecol(255, 105, 180); 121const int DEEPPINK = makecol(255, 20, 147); 122const int PINK = makecol(255, 192, 203); 123const int LIGHTPINK = makecol(255, 182, 193); 124const int PALEVIOLETRED = makecol(219, 112, 147); 125const int MAROON = makecol(176, 48, 96); 126const int MEDIUMVIOLETRED = makecol(199, 21, 133); 127const int VIOLETRED = makecol(208, 32, 144); 128const int MASK = makecol(255, 0, 255); 129const int VIOLET = makecol(238, 130, 238); 130const int PLUM = makecol(221, 160, 221); 131const int ORCHID = makecol(218, 112, 214); 132const int MEDIUMORCHID = makecol(186, 85, 211); 133const int DARKORCHID = makecol(153, 50, 204); 134const int DARKVIOLET = makecol(148, 0, 211); 135const int BLUEVIOLET = makecol(138, 43, 226); 136const int PURPLE = makecol(160, 32, 240); 137const int MEDIUMPURPLE = makecol(147, 112, 219); 138const int THISTLE = makecol(216, 191, 216); 139const int DARKGREY = makecol(169, 169, 169); 140const int DARKGRAY = makecol(169, 169, 169); 141const int DARKBLUE = makecol(0, 0, 139); 142const int DARKCYAN = makecol(0, 139, 139); 143const int DARKMAGENTA = makecol(139, 0, 139); 144const int DARKRED = makecol(139, 0, 0); 145const int LIGHTGREEN = makecol(144, 238, 144);

Now for some sample usage. I've written a simple button object that takes a back color (among other intital variables) and breaks down the color on its own functions and changes rgb settings to get its depth. Here's two buttons, one with SADDLEBROWN and the other as ROYALBLUE:

[img http://comp.uark.edu/~spsilve/button1.JPG]
[img http://comp.uark.edu/~spsilve/button2.JPG]

Maybe you can use it, maybe you can't. Just thought I'd offer. :)

------------
Solo-Games.org | My Tech Blog: The Digital Helm

kazzmir
Member #1,786
December 2001
avatar

I dont want to say its a bad idea, surely anything that lets you express colors in a more readable way is better but Ive never heard of most of those colors, much less know what r,g,b values they probably represent.

Kikaru
Member #7,616
August 2006
avatar

Looks handy. One thing that could help it: Define an array of references to allow easy indexing, then make an identical array of c-style strings to hold the names of the colors. It would make for a nice user interface usage. :)

LennyLen
Member #5,313
December 2004
avatar

Quote:

Define an array of references to allow easy indexing, then make an identical array of c-style strings to hold the names of the colors.

Why have two arrays? Create a struct that stores both the value and name and create one array of this struct.

Rick
Member #3,572
June 2003
avatar

Make it with C++, and use the stl map.

map<string, int> colors;

colors["white"] = makecol(255,255,255);

...

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Onewing
Member #6,152
August 2005
avatar

Hey, you guys do whatever you want with it. Although, I prefer WHITE over colors["white"]. ;)

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Andrei Ellman
Member #3,434
April 2003

Rick said:

map<string, int> colors;

colors["white"] = makecol(255,255,255);

This is starting to turn into another C++ Fractal.

AE.

--
Don't let the illegitimates turn you into carbon.

miran
Member #2,407
June 2002

In my endeavours to create a SVG rendering library I had to define a list of all standard named colours in SVG (which I think is the same as the standard CSS colours). I did it like this:

#SelectExpand
1static char *color_names[] = { 2 "aliceblue", 3 "antiquewhite", 4 "aqua", 5 "aquamarine", 6 "azure", 7 "beige", 8 "bisque", 9 "black", 10 "blanchedalmond", 11 "blue", 12 "blueviolet", 13 "brown", 14 "burlywood", 15 "cadetblue", 16 "chartreuse", 17 "chocolate", 18 "coral", 19 "cornflowerblue", 20 "cornsilk", 21 "crimson", 22 "cyan", 23 "darkblue", 24 "darkcyan", 25 "darkgoldenrod", 26 "darkgray", 27 "darkgreen", 28 "darkgrey", 29 "darkkhaki", 30 "darkmagenta", 31 "darkolivegreen", 32 "darkorange", 33 "darkorchid", 34 "darkred", 35 "darksalmon", 36 "darkseagreen", 37 "darkslateblue", 38 "darkslategray", 39 "darkslategrey", 40 "darkturquoise", 41 "darkviolet", 42 "deeppink", 43 "deepskyblue", 44 "dimgray", 45 "dimgrey", 46 "dodgerblue", 47 "firebrick", 48 "floralwhite", 49 "forestgreen", 50 "fuchsia", 51 "gainsboro", 52 "ghostwhite", 53 "gold", 54 "goldenrod", 55 "gray", 56 "grey", 57 "green", 58 "greenyellow", 59 "honeydew", 60 "hotpink", 61 "indianred", 62 "indigo", 63 "ivory", 64 "khaki", 65 "lavender", 66 "lavenderblush", 67 "lawngreen", 68 "lemonchiffon", 69 "lightblue", 70 "lightcoral", 71 "lightcyan", 72 "lightgoldenrodyellow", 73 "lightgray", 74 "lightgreen", 75 "lightgrey", 76 "lightpink", 77 "lightsalmon", 78 "lightseagreen", 79 "lightskyblue", 80 "lightslategray", 81 "lightslategrey", 82 "lightsteelblue", 83 "lightyellow", 84 "lime", 85 "limegreen", 86 "linen", 87 "magenta", 88 "maroon", 89 "mediumaquamarine", 90 "mediumblue", 91 "mediumorchid", 92 "mediumpurple", 93 "mediumseagreen", 94 "mediumslateblue", 95 "mediumspringgreen", 96 "mediumturquoise", 97 "mediumvioletred", 98 "midnightblue", 99 "mintcream", 100 "mistyrose", 101 "moccasin", 102 "navajowhite", 103 "navy", 104 "oldlace", 105 "olive", 106 "olivedrab", 107 "orange", 108 "orangered", 109 "orchid", 110 "palegoldenrod", 111 "palegreen", 112 "paleturquoise", 113 "palevioletred", 114 "papayawhip", 115 "peachpuff", 116 "peru", 117 "pink", 118 "plum", 119 "powderblue", 120 "purple", 121 "red", 122 "rosybrown", 123 "royalblue", 124 "saddlebrown", 125 "salmon", 126 "sandybrown", 127 "seagreen", 128 "seashell", 129 "sienna", 130 "silver", 131 "skyblue", 132 "slateblue", 133 "slategray", 134 "slategrey", 135 "snow", 136 "springgreen", 137 "steelblue", 138 "tan", 139 "teal", 140 "thistle", 141 "tomato", 142 "turquoise", 143 "violet", 144 "wheat", 145 "white", 146 "whitesmoke", 147 "yellow", 148 "yellowgreen", 149 0 150}; 151 152static char *color_rgb[] = { 153 "rgb(240, 248, 255)", 154 "rgb(250, 235, 215)", 155 "rgb( 0, 255, 255)", 156 "rgb(127, 255, 212)", 157 "rgb(240, 255, 255)", 158 "rgb(245, 245, 220)", 159 "rgb(255, 228, 196)", 160 "rgb( 0, 0, 0)", 161 "rgb(255, 235, 205)", 162 "rgb( 0, 0, 255)", 163 "rgb(138, 43, 226)", 164 "rgb(165, 42, 42)", 165 "rgb(222, 184, 135)", 166 "rgb( 95, 158, 160)", 167 "rgb(127, 255, 0)", 168 "rgb(210, 105, 30)", 169 "rgb(255, 127, 80)", 170 "rgb(100, 149, 237)", 171 "rgb(255, 248, 220)", 172 "rgb(220, 20, 60)", 173 "rgb( 0, 255, 255)", 174 "rgb( 0, 0, 139)", 175 "rgb( 0, 139, 139)", 176 "rgb(184, 134, 11)", 177 "rgb(169, 169, 169)", 178 "rgb( 0, 100, 0)", 179 "rgb(169, 169, 169)", 180 "rgb(189, 183, 107)", 181 "rgb(139, 0, 139)", 182 "rgb( 85, 107, 47)", 183 "rgb(255, 140, 0)", 184 "rgb(153, 50, 204)", 185 "rgb(139, 0, 0)", 186 "rgb(233, 150, 122)", 187 "rgb(143, 188, 143)", 188 "rgb( 72, 61, 139)", 189 "rgb( 47, 79, 79)", 190 "rgb( 47, 79, 79)", 191 "rgb( 0, 206, 209)", 192 "rgb(148, 0, 211)", 193 "rgb(255, 20, 147)", 194 "rgb( 0, 191, 255)", 195 "rgb(105, 105, 105)", 196 "rgb(105, 105, 105)", 197 "rgb( 30, 144, 255)", 198 "rgb(178, 34, 34)", 199 "rgb(255, 250, 240)", 200 "rgb( 34, 139, 34)", 201 "rgb(255, 0, 255)", 202 "rgb(220, 220, 220)", 203 "rgb(248, 248, 255)", 204 "rgb(255, 215, 0)", 205 "rgb(218, 165, 32)", 206 "rgb(128, 128, 128)", 207 "rgb(128, 128, 128)", 208 "rgb( 0, 128, 0)", 209 "rgb(173, 255, 47)", 210 "rgb(240, 255, 240)", 211 "rgb(255, 105, 180)", 212 "rgb(205, 92, 92)", 213 "rgb( 75, 0, 130)", 214 "rgb(255, 255, 240)", 215 "rgb(240, 230, 140)", 216 "rgb(230, 230, 250)", 217 "rgb(255, 240, 245)", 218 "rgb(124, 252, 0)", 219 "rgb(255, 250, 205)", 220 "rgb(173, 216, 230)", 221 "rgb(240, 128, 128)", 222 "rgb(224, 255, 255)", 223 "rgb(250, 250, 210)", 224 "rgb(211, 211, 211)", 225 "rgb(144, 238, 144)", 226 "rgb(211, 211, 211)", 227 "rgb(255, 182, 193)", 228 "rgb(255, 160, 122)", 229 "rgb( 32, 178, 170)", 230 "rgb(135, 206, 250)", 231 "rgb(119, 136, 153)", 232 "rgb(119, 136, 153)", 233 "rgb(176, 196, 222)", 234 "rgb(255, 255, 224)", 235 "rgb( 0, 255, 0)", 236 "rgb( 50, 205, 50)", 237 "rgb(250, 240, 230)", 238 "rgb(255, 0, 255)", 239 "rgb(128, 0, 0)", 240 "rgb(102, 205, 170)", 241 "rgb( 0, 0, 205)", 242 "rgb(186, 85, 211)", 243 "rgb(147, 112, 219)", 244 "rgb( 60, 179, 113)", 245 "rgb(123, 104, 238)", 246 "rgb( 0, 250, 154)", 247 "rgb( 72, 209, 204)", 248 "rgb(199, 21, 133)", 249 "rgb( 25, 25, 112)", 250 "rgb(245, 255, 250)", 251 "rgb(255, 228, 225)", 252 "rgb(255, 228, 181)", 253 "rgb(255, 222, 173)", 254 "rgb( 0, 0, 128)", 255 "rgb(253, 245, 230)", 256 "rgb(128, 128, 0)", 257 "rgb(107, 142, 35)", 258 "rgb(255, 165, 0)", 259 "rgb(255, 69, 0)", 260 "rgb(218, 112, 214)", 261 "rgb(238, 232, 170)", 262 "rgb(152, 251, 152)", 263 "rgb(175, 238, 238)", 264 "rgb(219, 112, 147)", 265 "rgb(255, 239, 213)", 266 "rgb(255, 218, 185)", 267 "rgb(205, 133, 63)", 268 "rgb(255, 192, 203)", 269 "rgb(221, 160, 221)", 270 "rgb(176, 224, 230)", 271 "rgb(128, 0, 128)", 272 "rgb(255, 0, 0)", 273 "rgb(188, 143, 143)", 274 "rgb( 65, 105, 225)", 275 "rgb(139, 69, 19)", 276 "rgb(250, 128, 114)", 277 "rgb(244, 164, 96)", 278 "rgb( 46, 139, 87)", 279 "rgb(255, 245, 238)", 280 "rgb(160, 82, 45)", 281 "rgb(192, 192, 192)", 282 "rgb(135, 206, 235)", 283 "rgb(106, 90, 205)", 284 "rgb(112, 128, 144)", 285 "rgb(112, 128, 144)", 286 "rgb(255, 250, 250)", 287 "rgb( 0, 255, 127)", 288 "rgb( 70, 130, 180)", 289 "rgb(210, 180, 140)", 290 "rgb( 0, 128, 128)", 291 "rgb(216, 191, 216)", 292 "rgb(255, 99, 71)", 293 "rgb( 64, 224, 208)", 294 "rgb(238, 130, 238)", 295 "rgb(245, 222, 179)", 296 "rgb(255, 255, 255)", 297 "rgb(245, 245, 245)", 298 "rgb(255, 255, 0)", 299 "rgb(154, 205, 50)", 300 0 301}; 302 303 304unsigned long hex_string_to_color(const std::string& valueAsString) { 305 // hex color specification 306 307 unsigned int col[3]; 308 int len = valueAsString.size()-1; 309 310 if (len < 3) { 311 return (unsigned long)(-1); 312 } 313 else if (len == 3) { 314 for (int i=0; i<3; i++) { 315 int c = valueAsString[i+1]; 316 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { 317 char buf[16]; 318 sprintf(buf, "0x%c%c", c, c); 319 sscanf(buf, "%x", &col<i>); 320 } 321 else { 322 return (unsigned long)(-1); 323 } 324 } 325 } 326 else if (len == 6) { 327 for (int i=0; i<6; i++) { 328 int c = valueAsString[i+1]; 329 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { 330 if (i%2 == 1) { 331 char buf[16]; 332 sprintf(buf, "0x%c%c", valueAsString<i>, valueAsString[i+1]); 333 sscanf(buf, "%x", &col[i/2]); 334 } 335 } 336 else { 337 return (unsigned long)(-1); 338 } 339 } 340 } 341 342 unsigned long ret = 0; 343 ret |= col[0]&0xff; 344 ret |= ((col[1]&0xff)<<8); 345 ret |= ((col[2]&0xff)<<16); 346 return ret; 347} 348 349 350unsigned long rgb_string_to_color(const std::string& valueAsString) { 351 int col[3]; 352 int count = sscanf(valueAsString.c_str(), "rgb(%d, %d, %d)", &col[0], &col[1], &col[2]); 353 354 if (count != 3) { 355 int count = sscanf(valueAsString.c_str(), "rgb(%d%%, %d%%, %d%%)", &col[0], &col[1], &col[2]); 356 if (count == 3) { 357 } 358 else { 359 return (unsigned long)(-1); 360 } 361 } 362 363 unsigned long ret = 0; 364 ret |= col[0]&0xff; 365 ret |= ((col[1]&0xff)<<8); 366 ret |= ((col[2]&0xff)<<16); 367 return ret; 368} 369 370 371unsigned long string_to_color(const std::string& valueAsString) { 372 if (valueAsString.size() < 1) { 373 return (unsigned long)(-1); 374 } 375 376 std::string tmp = valueAsString; 377 378 if (tmp[0] == '#') { 379 return hex_string_to_color(valueAsString); 380 } 381 else if (strncmp(tmp.c_str(), "rgb(", 4) == 0) { 382 // functional rgb specification 383 return rgb_string_to_color(valueAsString); 384 } 385 else { 386 // color name -> check against all known colors 387 int i=0; 388 while (color_names<i>) { 389 if (valueAsString == std::string(color_names<i>)) { 390 return rgb_string_to_color(color_rgb<i>); 391 } 392 393 ++i; 394 } 395 396 return (unsigned long)(-1); 397 } 398}

One can easily create an array of Allegro colour values, but I didn't actually need that...

--
sig used to be here

ixilom
Member #7,167
April 2006
avatar

I'm used to clBlack, clWhite and such from my time using Borland C++ Builder, so I've continued to do also with Allegro.
Although I don't have a predefined pretty file with XX colors, I just add them whenever I need a new color.
Also, rather than using integers taking up memory(I know, its not much but still) I do it with defines instead like:

#define clBlack makecol(0,0,0)
#define clWindow makecol(192,192,192)
#define clWindowBorder makecol(20,20,20)
etc..

___________________________________________
Democracy in Sweden? Not since 2008-Jun-18.
<someone> The lesbians next door bought me a rolex for my birthday.
<someone> I think they misunderstood when I said I wanna watch...

DanielH
Member #934
January 2001
avatar

Onewing:
Having those const's call makecol at start before the color depth is set, or by default 8bit, doesn't mess up at 15+bit color depth?

ixilom:
What's worse? Taking memory or calling a function every time you use cl######?

Neil Walker
Member #210
April 2000
avatar

I'm more perplexed by this:

Quote:

const int GRAY = makecol(60, 60, 60);
const int GREY = makecol(190, 190, 190);

Why do Americans/American English speaking people need a different shade of grey than the British English speaking world?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Johan Halmén
Member #1,550
September 2001

I wrote this in 10 minutes:

1const float red = 0;
2const float orange = 30;
3const float yellow = 60;
4const float green = 120;
5const float cyan = 180;
6const float blue = 240;
7const float magenta = 300;
8 
9float interpolate(float p1, float p2, float t);
10int colour(float hue, float sat, float val);
11 
12float interpolate(float p1, float p2, float t)
13{
14 return t * p2 + (1-t) * p1;
15}
16
17int colour(float hue, float sat, float val)
18{
19 int r, g, b;
20 hsv_to_rgb(hue, sat, val, &r, &g, &b);
21 return makecol(r, g, b);
22}

If I want a particular colour, say beige, I can pretty well guess where it is in a hsv world. The hue would be like orange, but saturation would be lower and the value raher high. So I would write:

my_beige = colour(orange, 0.5, 0.8);

And if I want some blue with a twist towards violet, I could interpolate:

my_indigo = colour(interpolate(blue, magenta, 0.1), 0.4, 1);

I think I get closer what I really want this way, instead of using some constants named SEASHELL. Well, I had to test two times on the latter one, before I got what I wanted.

[edit]
Well, the interpolation should have to take care of cases where the two colours are on both sides of hue = 360. The mean of 10 and 350 is not 180. It should be 0 or 360.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

miran
Member #2,407
June 2002

Quote:

If I want a particular colour, say beige, I can pretty well guess where it is in a hsv world.

The problem with this is that there's this thing called the International Colour Consortium (ICC) which sets these things called standards. There's a bunch of standard colour names with standard colour values. So if you're going to guess colour values, you'd better name them something like my_approximation_of_beige. Because "beige" is a standard name for the colour represented by rgb(245, 245, 220).

On the other hand different sets of standard colours are often used for different purposes anyway...

--
sig used to be here

Onewing
Member #6,152
August 2005
avatar

Quote:

Having those const's call makecol at start before the color depth is set, or by default 8bit, doesn't mess up at 15+bit color depth?

I don't know, haven't messed with it as of yet.

Quote:

What's worse? Taking memory or calling a function every time you use cl######?

To me, "calling a function every time" is worse than "taking memory", considering what all computers can handle these days. However, the list above is quite bloated, especially if you don't even use 90% of it in your program.

Quote:

Why do Americans/American English speaking people need a different shade of grey than the British English speaking world?

Yeah, I once called GRAY and then later called GREY for virtually the same background color and got two very different results. I was perplexed by this as well.

Quote:

I wrote this in 10 minutes:

Rock on.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

ixilom
Member #7,167
April 2006
avatar

Quote:

Onewing:
Having those const's call makecol at start before the color depth is set, or by default 8bit, doesn't mess up at 15+bit color depth?

ixilom:
What's worse? Taking memory or calling a function every time you use cl######?

You just answered the second quote with your first ::)

___________________________________________
Democracy in Sweden? Not since 2008-Jun-18.
<someone> The lesbians next door bought me a rolex for my birthday.
<someone> I think they misunderstood when I said I wanna watch...

DanielH
Member #934
January 2001
avatar

Actually, No I didn't.

It might not be much of a difference

60000000 Loops
Using Define: 4.7s
Using Int: 1.2s

600000000 Loops
Using Define: 50.0s
Using Int: 14.4s

Almost a 3:1 difference

1#include <allegro.h>
2#include <time.h>
3 
4#define dred makecol( 255, 0, 0 )
5 
6int ired = 0;
7 
8int useDef()
9{
10 return dred;
11}
12 
13int useInt()
14{
15 return ired;
16}
17 
18 
19int main( int argc, char **argv )
20{
21 int p = 0;
22 clock_t s1 = 0;
23 clock_t f1 = 0;
24 clock_t s2 = 0;
25 clock_t f2 = 0;
26 double d1 = 0.0;
27 double d2 = 0.0;
28 
29 
30 allegro_init();
31 
32 set_color_depth( 32 );
33 
34 ired = makecol( 255, 0, 0 );
35 
36 s1 = clock();
37 
38 for ( int i = 0; i < 60000000; i++ )
39 {
40 p = useDef();
41 }
42 
43 f1 = clock();
44 
45 s2 = clock();
46 
47 for ( int i = 0; i < 60000000; i++ )
48 {
49 p = useInt();
50 }
51 
52 f2 = clock();
53 
54 d1 = (double)(f1 - s1) / CLOCKS_PER_SEC;
55 
56 d2 = (double)(f2 - s2) / CLOCKS_PER_SEC;
57 
58 printf( "Using Define: %2.1fs\n"
59 "Using Int: %2.1fs\n", d1, d2 );
60 
61 return 0;
62}
63END_OF_MAIN()

ixilom
Member #7,167
April 2006
avatar

I know there will be a timedifference, but set your bit depth to something else, assign a color to an int with another bit depth.
We don't want that now do we?

___________________________________________
Democracy in Sweden? Not since 2008-Jun-18.
<someone> The lesbians next door bought me a rolex for my birthday.
<someone> I think they misunderstood when I said I wanna watch...

Arvidsson
Member #4,603
May 2004
avatar

That's simple to avoid though, by assigning the variables after setting the color depth.

DanielH
Member #934
January 2001
avatar

That's basically what I do.

I reset the colors everytime the color depth changes.

Go to: