WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
Color.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <algorithm>
8#include <cstdint>
9#include <stdexcept>
10#include <string>
11#include <string_view>
12
13#include <fmt/format.h>
14
15#include "wpi/util/StringExtras.hpp"
17
18namespace wpi::util {
19
20// replicate ceil from gcem to avoid gcem dependency here
21namespace detail {
22constexpr double ceil_int(double x, double x_whole) noexcept {
23 return (x_whole + ((x > 0) && (x > x_whole)));
24}
25
26constexpr double ceil(double x) noexcept {
27 if (std::is_constant_evaluated()) {
28 return ((x < 0.0 ? -x : x) >= 4503599627370496.
29 ? x
30 : ceil_int(x, static_cast<double>(static_cast<int64_t>(x))));
31 } else {
32 return std::ceil(x);
33 }
34}
35} // namespace detail
36
37/**
38 * Represents colors that can be used with Addressable LEDs.
39 *
40 * Limited to 12 bits of precision.
41 */
42class Color {
43 public:
44 /*
45 * FIRST Colors
46 */
47
48 /**
49 * 0x1560BD.
50 */
51 static const Color DENIM;
52
53 /**
54 * 0x0066B3.
55 */
56 static const Color FIRST_BLUE;
57
58 /**
59 * 0xED1C24.
60 */
61 static const Color FIRST_RED;
62
63 /*
64 * Standard Colors
65 */
66
67 /**
68 * 0xF0F8FF.
69 */
70 static const Color ALICE_BLUE;
71
72 /**
73 * 0xFAEBD7.
74 */
75 static const Color ANTIQUE_WHITE;
76
77 /**
78 * 0x00FFFF.
79 */
80 static const Color AQUA;
81
82 /**
83 * 0x7FFFD4.
84 */
85 static const Color AQUAMARINE;
86
87 /**
88 * 0xF0FFFF.
89 */
90 static const Color AZURE;
91
92 /**
93 * 0xF5F5DC.
94 */
95 static const Color BEIGE;
96
97 /**
98 * 0xFFE4C4.
99 */
100 static const Color BISQUE;
101
102 /**
103 * 0x000000.
104 */
105 static const Color BLACK;
106
107 /**
108 * 0xFFEBCD.
109 */
110 static const Color BLANCHED_ALMOND;
111
112 /**
113 * 0x0000FF.
114 */
115 static const Color BLUE;
116
117 /**
118 * 0x8A2BE2.
119 */
120 static const Color BLUE_VIOLET;
121
122 /**
123 * 0xA52A2A.
124 */
125 static const Color BROWN;
126
127 /**
128 * 0xDEB887.
129 */
130 static const Color BURLYWOOD;
131
132 /**
133 * 0x5F9EA0.
134 */
135 static const Color CADET_BLUE;
136
137 /**
138 * 0x7FFF00.
139 */
140 static const Color CHARTREUSE;
141
142 /**
143 * 0xD2691E.
144 */
145 static const Color CHOCOLATE;
146
147 /**
148 * 0xFF7F50.
149 */
150 static const Color CORAL;
151
152 /**
153 * 0x6495ED.
154 */
155 static const Color CORNFLOWER_BLUE;
156
157 /**
158 * 0xFFF8DC.
159 */
160 static const Color CORNSILK;
161
162 /**
163 * 0xDC143C.
164 */
165 static const Color CRIMSON;
166
167 /**
168 * 0x00FFFF.
169 */
170 static const Color CYAN;
171
172 /**
173 * 0x00008B.
174 */
175 static const Color DARK_BLUE;
176
177 /**
178 * 0x008B8B.
179 */
180 static const Color DARK_CYAN;
181
182 /**
183 * 0xB8860B.
184 */
185 static const Color DARK_GOLDENROD;
186
187 /**
188 * 0xA9A9A9.
189 */
190 static const Color DARK_GRAY;
191
192 /**
193 * 0x006400.
194 */
195 static const Color DARK_GREEN;
196
197 /**
198 * 0xBDB76B.
199 */
200 static const Color DARK_KHAKI;
201
202 /**
203 * 0x8B008B.
204 */
205 static const Color DARK_MAGENTA;
206
207 /**
208 * 0x556B2F.
209 */
211
212 /**
213 * 0xFF8C00.
214 */
215 static const Color DARK_ORANGE;
216
217 /**
218 * 0x9932CC.
219 */
220 static const Color DARK_ORCHID;
221
222 /**
223 * 0x8B0000.
224 */
225 static const Color DARK_RED;
226
227 /**
228 * 0xE9967A.
229 */
230 static const Color DARK_SALMON;
231
232 /**
233 * 0x8FBC8F.
234 */
235 static const Color DARK_SEA_GREEN;
236
237 /**
238 * 0x483D8B.
239 */
240 static const Color DARK_SLATE_BLUE;
241
242 /**
243 * 0x2F4F4F.
244 */
245 static const Color DARK_SLATE_GRAY;
246
247 /**
248 * 0x00CED1.
249 */
250 static const Color DARK_TURQUOISE;
251
252 /**
253 * 0x9400D3.
254 */
255 static const Color DARK_VIOLET;
256
257 /**
258 * 0xFF1493.
259 */
260 static const Color DEEP_PINK;
261
262 /**
263 * 0x00BFFF.
264 */
265 static const Color DEEP_SKY_BLUE;
266
267 /**
268 * 0x696969.
269 */
270 static const Color DIM_GRAY;
271
272 /**
273 * 0x1E90FF.
274 */
275 static const Color DODGER_BLUE;
276
277 /**
278 * 0xB22222.
279 */
280 static const Color FIREBRICK;
281
282 /**
283 * 0xFFFAF0.
284 */
285 static const Color FLORAL_WHITE;
286
287 /**
288 * 0x228B22.
289 */
290 static const Color FOREST_GREEN;
291
292 /**
293 * 0xFF00FF.
294 */
295 static const Color FUCHSIA;
296
297 /**
298 * 0xDCDCDC.
299 */
300 static const Color GAINSBORO;
301
302 /**
303 * 0xF8F8FF.
304 */
305 static const Color GHOST_WHITE;
306
307 /**
308 * 0xFFD700.
309 */
310 static const Color GOLD;
311
312 /**
313 * 0xDAA520.
314 */
315 static const Color GOLDENROD;
316
317 /**
318 * 0x808080.
319 */
320 static const Color GRAY;
321
322 /**
323 * 0x008000.
324 */
325 static const Color GREEN;
326
327 /**
328 * 0xADFF2F.
329 */
330 static const Color GREEN_YELLOW;
331
332 /**
333 * 0xF0FFF0.
334 */
335 static const Color HONEYDEW;
336
337 /**
338 * 0xFF69B4.
339 */
340 static const Color HOT_PINK;
341
342 /**
343 * 0xCD5C5C.
344 */
345 static const Color INDIAN_RED;
346
347 /**
348 * 0x4B0082.
349 */
350 static const Color INDIGO;
351
352 /**
353 * 0xFFFFF0.
354 */
355 static const Color IVORY;
356
357 /**
358 * 0xF0E68C.
359 */
360 static const Color KHAKI;
361
362 /**
363 * 0xE6E6FA.
364 */
365 static const Color LAVENDER;
366
367 /**
368 * 0xFFF0F5.
369 */
370 static const Color LAVENDER_BLUSH;
371
372 /**
373 * 0x7CFC00.
374 */
375 static const Color LAWN_GREEN;
376
377 /**
378 * 0xFFFACD.
379 */
380 static const Color LEMON_CHIFFON;
381
382 /**
383 * 0xADD8E6.
384 */
385 static const Color LIGHT_BLUE;
386
387 /**
388 * 0xF08080.
389 */
390 static const Color LIGHT_CORAL;
391
392 /**
393 * 0xE0FFFF.
394 */
395 static const Color LIGHT_CYAN;
396
397 /**
398 * 0xFAFAD2.
399 */
401
402 /**
403 * 0xD3D3D3.
404 */
405 static const Color LIGHT_GRAY;
406
407 /**
408 * 0x90EE90.
409 */
410 static const Color LIGHT_GREEN;
411
412 /**
413 * 0xFFB6C1.
414 */
415 static const Color LIGHT_PINK;
416
417 /**
418 * 0xFFA07A.
419 */
420 static const Color LIGHT_SALMON;
421
422 /**
423 * 0x20B2AA.
424 */
425 static const Color LIGHT_SEA_GREEN;
426
427 /**
428 * 0x87CEFA.
429 */
430 static const Color LIGHT_SKY_BLUE;
431
432 /**
433 * 0x778899.
434 */
436
437 /**
438 * 0xB0C4DE.
439 */
441
442 /**
443 * 0xFFFFE0.
444 */
445 static const Color LIGHT_YELLOW;
446
447 /**
448 * 0x00FF00.
449 */
450 static const Color LIME;
451
452 /**
453 * 0x32CD32.
454 */
455 static const Color LIME_GREEN;
456
457 /**
458 * 0xFAF0E6.
459 */
460 static const Color LINEN;
461
462 /**
463 * 0xFF00FF.
464 */
465 static const Color MAGENTA;
466
467 /**
468 * 0x800000.
469 */
470 static const Color MAROON;
471
472 /**
473 * 0x66CDAA.
474 */
476
477 /**
478 * 0x0000CD.
479 */
480 static const Color MEDIUM_BLUE;
481
482 /**
483 * 0xBA55D3.
484 */
485 static const Color MEDIUM_ORCHID;
486
487 /**
488 * 0x9370DB.
489 */
490 static const Color MEDIUM_PURPLE;
491
492 /**
493 * 0x3CB371.
494 */
496
497 /**
498 * 0x7B68EE.
499 */
501
502 /**
503 * 0x00FA9A.
504 */
506
507 /**
508 * 0x48D1CC.
509 */
511
512 /**
513 * 0xC71585.
514 */
516
517 /**
518 * 0x191970.
519 */
520 static const Color MIDNIGHT_BLUE;
521
522 /**
523 * 0xF5FFFA.
524 */
525 static const Color MINTCREAM;
526
527 /**
528 * 0xFFE4E1.
529 */
530 static const Color MISTY_ROSE;
531
532 /**
533 * 0xFFE4B5.
534 */
535 static const Color MOCCASIN;
536
537 /**
538 * 0xFFDEAD.
539 */
540 static const Color NAVAJO_WHITE;
541
542 /**
543 * 0x000080.
544 */
545 static const Color NAVY;
546
547 /**
548 * 0xFDF5E6.
549 */
550 static const Color OLD_LACE;
551
552 /**
553 * 0x808000.
554 */
555 static const Color OLIVE;
556
557 /**
558 * 0x6B8E23.
559 */
560 static const Color OLIVE_DRAB;
561
562 /**
563 * 0xFFA500.
564 */
565 static const Color ORANGE;
566
567 /**
568 * 0xFF4500.
569 */
570 static const Color ORANGE_RED;
571
572 /**
573 * 0xDA70D6.
574 */
575 static const Color ORCHID;
576
577 /**
578 * 0xEEE8AA.
579 */
580 static const Color PALE_GOLDENROD;
581
582 /**
583 * 0x98FB98.
584 */
585 static const Color PALE_GREEN;
586
587 /**
588 * 0xAFEEEE.
589 */
590 static const Color PALE_TURQUOISE;
591
592 /**
593 * 0xDB7093.
594 */
595 static const Color PALE_VIOLET_RED;
596
597 /**
598 * 0xFFEFD5.
599 */
600 static const Color PAPAYA_WHIP;
601
602 /**
603 * 0xFFDAB9.
604 */
605 static const Color PEACH_PUFF;
606
607 /**
608 * 0xCD853F.
609 */
610 static const Color PERU;
611
612 /**
613 * 0xFFC0CB.
614 */
615 static const Color PINK;
616
617 /**
618 * 0xDDA0DD.
619 */
620 static const Color PLUM;
621
622 /**
623 * 0xB0E0E6.
624 */
625 static const Color POWDER_BLUE;
626
627 /**
628 * 0x800080.
629 */
630 static const Color PURPLE;
631
632 /**
633 * 0xFF0000.
634 */
635 static const Color RED;
636
637 /**
638 * 0xBC8F8F.
639 */
640 static const Color ROSY_BROWN;
641
642 /**
643 * 0x4169E1.
644 */
645 static const Color ROYAL_BLUE;
646
647 /**
648 * 0x8B4513.
649 */
650 static const Color SADDLE_BROWN;
651
652 /**
653 * 0xFA8072.
654 */
655 static const Color SALMON;
656
657 /**
658 * 0xF4A460.
659 */
660 static const Color SANDY_BROWN;
661
662 /**
663 * 0x2E8B57.
664 */
665 static const Color SEA_GREEN;
666
667 /**
668 * 0xFFF5EE.
669 */
670 static const Color SEASHELL;
671
672 /**
673 * 0xA0522D.
674 */
675 static const Color SIENNA;
676
677 /**
678 * 0xC0C0C0.
679 */
680 static const Color SILVER;
681
682 /**
683 * 0x87CEEB.
684 */
685 static const Color SKY_BLUE;
686
687 /**
688 * 0x6A5ACD.
689 */
690 static const Color SLATE_BLUE;
691
692 /**
693 * 0x708090.
694 */
695 static const Color SLATE_GRAY;
696
697 /**
698 * 0xFFFAFA.
699 */
700 static const Color SNOW;
701
702 /**
703 * 0x00FF7F.
704 */
705 static const Color SPRING_GREEN;
706
707 /**
708 * 0x4682B4.
709 */
710 static const Color STEEL_BLUE;
711
712 /**
713 * 0xD2B48C.
714 */
715 static const Color TAN;
716
717 /**
718 * 0x008080.
719 */
720 static const Color TEAL;
721
722 /**
723 * 0xD8BFD8.
724 */
725 static const Color THISTLE;
726
727 /**
728 * 0xFF6347.
729 */
730 static const Color TOMATO;
731
732 /**
733 * 0x40E0D0.
734 */
735 static const Color TURQUOISE;
736
737 /**
738 * 0xEE82EE.
739 */
740 static const Color VIOLET;
741
742 /**
743 * 0xF5DEB3.
744 */
745 static const Color WHEAT;
746
747 /**
748 * 0xFFFFFF.
749 */
750 static const Color WHITE;
751
752 /**
753 * 0xF5F5F5.
754 */
755 static const Color WHITE_SMOKE;
756
757 /**
758 * 0xFFFF00.
759 */
760 static const Color YELLOW;
761
762 /**
763 * 0x9ACD32.
764 */
765 static const Color YELLOW_GREEN;
766
767 /**
768 * Constructs a default color (black).
769 */
770 constexpr Color() = default;
771
772 /**
773 * Constructs a Color from doubles (0-1).
774 *
775 * @param r Red value (0-1)
776 * @param g Green value (0-1)
777 * @param b Blue value (0-1)
778 */
779 constexpr Color(double r, double g, double b)
780 : red(roundAndClamp(r)),
781 green(roundAndClamp(g)),
782 blue(roundAndClamp(b)) {}
783
784 /**
785 * Constructs a Color from ints (0-255).
786 *
787 * @param r Red value (0-255)
788 * @param g Green value (0-255)
789 * @param b Blue value (0-255)
790 */
791 constexpr Color(int r, int g, int b)
792 : Color(r / 255.0, g / 255.0, b / 255.0) {}
793
794 constexpr bool operator==(const Color&) const = default;
795
796 /**
797 * Makes a Color from a string.
798 *
799 * @param str a string of the format `#RRGGBB` or `rgb(R, G, B)`
800 * @return the Color
801 * @throws std::invalid_argument if the hex string is invalid.
802 */
803 static constexpr Color FromString(std::string_view str) {
804 if (str.empty()) {
805 throw std::invalid_argument(
806 fmt::format("Invalid color string \"{}\"", str));
807 }
808
809 // #RRGGBB style
810 if (str[0] == '#') {
811 if (str.length() != 7 || !str.starts_with("#") ||
812 !wpi::util::isHexDigit(str[1]) || !wpi::util::isHexDigit(str[2]) ||
813 !wpi::util::isHexDigit(str[3]) || !wpi::util::isHexDigit(str[4]) ||
814 !wpi::util::isHexDigit(str[5]) || !wpi::util::isHexDigit(str[6])) {
815 throw std::invalid_argument(
816 fmt::format("Invalid hex string \"{}\"", str));
817 }
818
819 int r = wpi::util::hexDigitValue(str[1]) * 16 +
820 wpi::util::hexDigitValue(str[2]);
821 int g = wpi::util::hexDigitValue(str[3]) * 16 +
822 wpi::util::hexDigitValue(str[4]);
823 int b = wpi::util::hexDigitValue(str[5]) * 16 +
824 wpi::util::hexDigitValue(str[6]);
825
826 return Color(r, g, b);
827 }
828
829 // RGB style
830 if (str.starts_with("rgb(") && str.ends_with(")")) {
831 auto [redStr, gbStr] =
832 wpi::util::split(wpi::util::slice(str, 4, str.length() - 1), ',');
833 auto [greenStr, blueStr] = wpi::util::split(gbStr, ',');
834 if (blueStr.empty()) {
835 throw std::invalid_argument(
836 fmt::format("Invalid RGB string \"{}\"", str));
837 }
838 auto r = wpi::util::parse_integer<uint8_t>(wpi::util::trim(redStr), 10);
839 auto g = wpi::util::parse_integer<uint8_t>(wpi::util::trim(greenStr), 10);
840 auto b = wpi::util::parse_integer<uint8_t>(wpi::util::trim(blueStr), 10);
841 if (!r || !g || !b) {
842 throw std::invalid_argument(
843 fmt::format("Invalid RGB string \"{}\"", str));
844 }
845 return Color(*r, *g, *b);
846 }
847
848 throw std::invalid_argument(
849 fmt::format("Invalid color string \"{}\"", str));
850 }
851
852 /**
853 * Creates a Color from HSV values.
854 *
855 * @param h The h value [0-180)
856 * @param s The s value [0-255]
857 * @param v The v value [0-255]
858 * @return The color
859 */
860 static constexpr Color FromHSV(int h, int s, int v) {
861 // Loosely based on
862 // https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
863 // The hue range is split into 60 degree regions where in each region there
864 // is one rgb component at a low value (m), one at a high value (v) and one
865 // that changes (X) from low to high (X+m) or high to low (v-X)
866
867 // Difference between highest and lowest value of any rgb component
868 int chroma = (s * v) / 255;
869
870 // Because hue is 0-180 rather than 0-360 use 30 not 60
871 int region = (h / 30) % 6;
872
873 // Remainder converted from 0-30 to 0-255
874 int remainder = static_cast<int>((h % 30) * (255 / 30.0));
875
876 // Value of the lowest rgb component
877 int m = v - chroma;
878
879 // Goes from 0 to chroma as hue increases
880 int X = (chroma * remainder) >> 8;
881
882 switch (region) {
883 case 0:
884 return Color(v, X + m, m);
885 case 1:
886 return Color(v - X, v, m);
887 case 2:
888 return Color(m, v, X + m);
889 case 3:
890 return Color(m, v - X, v);
891 case 4:
892 return Color(X + m, m, v);
893 default:
894 return Color(v, m, v - X);
895 }
896 }
897
898 /**
899 * Return this color represented as a hex string.
900 *
901 * @return a string of the format <tt>\#RRGGBB</tt>
902 */
903 constexpr auto HexString() const {
904 const int r = 255.0 * red;
905 const int g = 255.0 * green;
906 const int b = 255.0 * blue;
907
909 {'#', wpi::util::hexdigit(r / 16), wpi::util::hexdigit(r % 16),
910 wpi::util::hexdigit(g / 16), wpi::util::hexdigit(g % 16),
911 wpi::util::hexdigit(b / 16), wpi::util::hexdigit(b % 16)}};
912 }
913
914 /// Red component (0-1).
915 double red = 0.0;
916
917 /// Green component (0-1).
918 double green = 0.0;
919
920 /// Blue component (0-1).
921 double blue = 0.0;
922
923 private:
924 static constexpr double roundAndClamp(double value) {
925 return std::clamp(detail::ceil(value * (1 << 12)) / (1 << 12), 0.0, 1.0);
926 }
927};
928
929/*
930 * FIRST Colors
931 */
932inline constexpr Color Color::DENIM{0.0823529412, 0.376470589, 0.7411764706};
933inline constexpr Color Color::FIRST_BLUE{0.0, 0.4, 0.7019607844};
934inline constexpr Color Color::FIRST_RED{0.9294117648, 0.1098039216,
935 0.1411764706};
936
937/*
938 * Standard Colors
939 */
940inline constexpr Color Color::ALICE_BLUE{0.9411765f, 0.972549f, 1.0f};
941inline constexpr Color Color::ANTIQUE_WHITE{0.98039216f, 0.92156863f,
942 0.84313726f};
943inline constexpr Color Color::AQUA{0.0f, 1.0f, 1.0f};
944inline constexpr Color Color::AQUAMARINE{0.49803922f, 1.0f, 0.83137256f};
945inline constexpr Color Color::AZURE{0.9411765f, 1.0f, 1.0f};
946inline constexpr Color Color::BEIGE{0.9607843f, 0.9607843f, 0.8627451f};
947inline constexpr Color Color::BISQUE{1.0f, 0.89411765f, 0.76862746f};
948inline constexpr Color Color::BLACK{0.0f, 0.0f, 0.0f};
949inline constexpr Color Color::BLANCHED_ALMOND{1.0f, 0.92156863f, 0.8039216f};
950inline constexpr Color Color::BLUE{0.0f, 0.0f, 1.0f};
951inline constexpr Color Color::BLUE_VIOLET{0.5411765f, 0.16862746f, 0.8862745f};
952inline constexpr Color Color::BROWN{0.64705884f, 0.16470589f, 0.16470589f};
953inline constexpr Color Color::BURLYWOOD{0.87058824f, 0.72156864f, 0.5294118f};
954inline constexpr Color Color::CADET_BLUE{0.37254903f, 0.61960787f, 0.627451f};
955inline constexpr Color Color::CHARTREUSE{0.49803922f, 1.0f, 0.0f};
956inline constexpr Color Color::CHOCOLATE{0.8235294f, 0.4117647f, 0.11764706f};
957inline constexpr Color Color::CORAL{1.0f, 0.49803922f, 0.3137255f};
958inline constexpr Color Color::CORNFLOWER_BLUE{0.39215687f, 0.58431375f,
959 0.92941177f};
960inline constexpr Color Color::CORNSILK{1.0f, 0.972549f, 0.8627451f};
961inline constexpr Color Color::CRIMSON{0.8627451f, 0.078431375f, 0.23529412f};
962inline constexpr Color Color::CYAN{0.0f, 1.0f, 1.0f};
963inline constexpr Color Color::DARK_BLUE{0.0f, 0.0f, 0.54509807f};
964inline constexpr Color Color::DARK_CYAN{0.0f, 0.54509807f, 0.54509807f};
965inline constexpr Color Color::DARK_GOLDENROD{0.72156864f, 0.5254902f,
966 0.043137256f};
967inline constexpr Color Color::DARK_GRAY{0.6627451f, 0.6627451f, 0.6627451f};
968inline constexpr Color Color::DARK_GREEN{0.0f, 0.39215687f, 0.0f};
969inline constexpr Color Color::DARK_KHAKI{0.7411765f, 0.7176471f, 0.41960785f};
970inline constexpr Color Color::DARK_MAGENTA{0.54509807f, 0.0f, 0.54509807f};
971inline constexpr Color Color::DARK_OLIVE_GREEN{0.33333334f, 0.41960785f,
972 0.18431373f};
973inline constexpr Color Color::DARK_ORANGE{1.0f, 0.54901963f, 0.0f};
974inline constexpr Color Color::DARK_ORCHID{0.6f, 0.19607843f, 0.8f};
975inline constexpr Color Color::DARK_RED{0.54509807f, 0.0f, 0.0f};
976inline constexpr Color Color::DARK_SALMON{0.9137255f, 0.5882353f, 0.47843137f};
977inline constexpr Color Color::DARK_SEA_GREEN{0.56078434f, 0.7372549f,
978 0.56078434f};
979inline constexpr Color Color::DARK_SLATE_BLUE{0.28235295f, 0.23921569f,
980 0.54509807f};
981inline constexpr Color Color::DARK_SLATE_GRAY{0.18431373f, 0.30980393f,
982 0.30980393f};
983inline constexpr Color Color::DARK_TURQUOISE{0.0f, 0.80784315f, 0.81960785f};
984inline constexpr Color Color::DARK_VIOLET{0.5803922f, 0.0f, 0.827451f};
985inline constexpr Color Color::DEEP_PINK{1.0f, 0.078431375f, 0.5764706f};
986inline constexpr Color Color::DEEP_SKY_BLUE{0.0f, 0.7490196f, 1.0f};
987inline constexpr Color Color::DIM_GRAY{0.4117647f, 0.4117647f, 0.4117647f};
988inline constexpr Color Color::DODGER_BLUE{0.11764706f, 0.5647059f, 1.0f};
989inline constexpr Color Color::FIREBRICK{0.69803923f, 0.13333334f, 0.13333334f};
990inline constexpr Color Color::FLORAL_WHITE{1.0f, 0.98039216f, 0.9411765f};
991inline constexpr Color Color::FOREST_GREEN{0.13333334f, 0.54509807f,
992 0.13333334f};
993inline constexpr Color Color::FUCHSIA{1.0f, 0.0f, 1.0f};
994inline constexpr Color Color::GAINSBORO{0.8627451f, 0.8627451f, 0.8627451f};
995inline constexpr Color Color::GHOST_WHITE{0.972549f, 0.972549f, 1.0f};
996inline constexpr Color Color::GOLD{1.0f, 0.84313726f, 0.0f};
997inline constexpr Color Color::GOLDENROD{0.85490197f, 0.64705884f, 0.1254902f};
998inline constexpr Color Color::GRAY{0.5019608f, 0.5019608f, 0.5019608f};
999inline constexpr Color Color::GREEN{0.0f, 0.5019608f, 0.0f};
1000inline constexpr Color Color::GREEN_YELLOW{0.6784314f, 1.0f, 0.18431373f};
1001inline constexpr Color Color::HONEYDEW{0.9411765f, 1.0f, 0.9411765f};
1002inline constexpr Color Color::HOT_PINK{1.0f, 0.4117647f, 0.7058824f};
1003inline constexpr Color Color::INDIAN_RED{0.8039216f, 0.36078432f, 0.36078432f};
1004inline constexpr Color Color::INDIGO{0.29411766f, 0.0f, 0.50980395f};
1005inline constexpr Color Color::IVORY{1.0f, 1.0f, 0.9411765f};
1006inline constexpr Color Color::KHAKI{0.9411765f, 0.9019608f, 0.54901963f};
1007inline constexpr Color Color::LAVENDER{0.9019608f, 0.9019608f, 0.98039216f};
1008inline constexpr Color Color::LAVENDER_BLUSH{1.0f, 0.9411765f, 0.9607843f};
1009inline constexpr Color Color::LAWN_GREEN{0.4862745f, 0.9882353f, 0.0f};
1010inline constexpr Color Color::LEMON_CHIFFON{1.0f, 0.98039216f, 0.8039216f};
1011inline constexpr Color Color::LIGHT_BLUE{0.6784314f, 0.84705883f, 0.9019608f};
1012inline constexpr Color Color::LIGHT_CORAL{0.9411765f, 0.5019608f, 0.5019608f};
1013inline constexpr Color Color::LIGHT_CYAN{0.8784314f, 1.0f, 1.0f};
1014inline constexpr Color Color::LIGHT_GOLDENROD_YELLOW{0.98039216f, 0.98039216f,
1015 0.8235294f};
1016inline constexpr Color Color::LIGHT_GRAY{0.827451f, 0.827451f, 0.827451f};
1017inline constexpr Color Color::LIGHT_GREEN{0.5647059f, 0.93333334f, 0.5647059f};
1018inline constexpr Color Color::LIGHT_PINK{1.0f, 0.7137255f, 0.75686276f};
1019inline constexpr Color Color::LIGHT_SALMON{1.0f, 0.627451f, 0.47843137f};
1020inline constexpr Color Color::LIGHT_SEA_GREEN{0.1254902f, 0.69803923f,
1021 0.6666667f};
1022inline constexpr Color Color::LIGHT_SKY_BLUE{0.5294118f, 0.80784315f,
1023 0.98039216f};
1024inline constexpr Color Color::LIGHT_SLATE_GRAY{0.46666667f, 0.53333336f, 0.6f};
1025inline constexpr Color Color::LIGHT_STEEL_BLUE{0.6901961f, 0.76862746f,
1026 0.87058824f};
1027inline constexpr Color Color::LIGHT_YELLOW{1.0f, 1.0f, 0.8784314f};
1028inline constexpr Color Color::LIME{0.0f, 1.0f, 0.0f};
1029inline constexpr Color Color::LIME_GREEN{0.19607843f, 0.8039216f, 0.19607843f};
1030inline constexpr Color Color::LINEN{0.98039216f, 0.9411765f, 0.9019608f};
1031inline constexpr Color Color::MAGENTA{1.0f, 0.0f, 1.0f};
1032inline constexpr Color Color::MAROON{0.5019608f, 0.0f, 0.0f};
1033inline constexpr Color Color::MEDIUM_AQUAMARINE{0.4f, 0.8039216f, 0.6666667f};
1034inline constexpr Color Color::MEDIUM_BLUE{0.0f, 0.0f, 0.8039216f};
1035inline constexpr Color Color::MEDIUM_ORCHID{0.7294118f, 0.33333334f, 0.827451f};
1036inline constexpr Color Color::MEDIUM_PURPLE{0.5764706f, 0.4392157f,
1037 0.85882354f};
1038inline constexpr Color Color::MEDIUM_SEA_GREEN{0.23529412f, 0.7019608f,
1039 0.44313726f};
1040inline constexpr Color Color::MEDIUM_SLATE_BLUE{0.48235294f, 0.40784314f,
1041 0.93333334f};
1042inline constexpr Color Color::MEDIUM_SPRING_GREEN{0.0f, 0.98039216f,
1043 0.6039216f};
1044inline constexpr Color Color::MEDIUM_TURQUOISE{0.28235295f, 0.81960785f, 0.8f};
1045inline constexpr Color Color::MEDIUM_VIOLET_RED{0.78039217f, 0.08235294f,
1046 0.52156866f};
1047inline constexpr Color Color::MIDNIGHT_BLUE{0.09803922f, 0.09803922f,
1048 0.4392157f};
1049inline constexpr Color Color::MINTCREAM{0.9607843f, 1.0f, 0.98039216f};
1050inline constexpr Color Color::MISTY_ROSE{1.0f, 0.89411765f, 0.88235295f};
1051inline constexpr Color Color::MOCCASIN{1.0f, 0.89411765f, 0.70980394f};
1052inline constexpr Color Color::NAVAJO_WHITE{1.0f, 0.87058824f, 0.6784314f};
1053inline constexpr Color Color::NAVY{0.0f, 0.0f, 0.5019608f};
1054inline constexpr Color Color::OLD_LACE{0.99215686f, 0.9607843f, 0.9019608f};
1055inline constexpr Color Color::OLIVE{0.5019608f, 0.5019608f, 0.0f};
1056inline constexpr Color Color::OLIVE_DRAB{0.41960785f, 0.5568628f, 0.13725491f};
1057inline constexpr Color Color::ORANGE{1.0f, 0.64705884f, 0.0f};
1058inline constexpr Color Color::ORANGE_RED{1.0f, 0.27058825f, 0.0f};
1059inline constexpr Color Color::ORCHID{0.85490197f, 0.4392157f, 0.8392157f};
1060inline constexpr Color Color::PALE_GOLDENROD{0.93333334f, 0.9098039f,
1061 0.6666667f};
1062inline constexpr Color Color::PALE_GREEN{0.59607846f, 0.9843137f, 0.59607846f};
1063inline constexpr Color Color::PALE_TURQUOISE{0.6862745f, 0.93333334f,
1064 0.93333334f};
1065inline constexpr Color Color::PALE_VIOLET_RED{0.85882354f, 0.4392157f,
1066 0.5764706f};
1067inline constexpr Color Color::PAPAYA_WHIP{1.0f, 0.9372549f, 0.8352941f};
1068inline constexpr Color Color::PEACH_PUFF{1.0f, 0.85490197f, 0.7254902f};
1069inline constexpr Color Color::PERU{0.8039216f, 0.52156866f, 0.24705882f};
1070inline constexpr Color Color::PINK{1.0f, 0.7529412f, 0.79607844f};
1071inline constexpr Color Color::PLUM{0.8666667f, 0.627451f, 0.8666667f};
1072inline constexpr Color Color::POWDER_BLUE{0.6901961f, 0.8784314f, 0.9019608f};
1073inline constexpr Color Color::PURPLE{0.5019608f, 0.0f, 0.5019608f};
1074inline constexpr Color Color::RED{1.0f, 0.0f, 0.0f};
1075inline constexpr Color Color::ROSY_BROWN{0.7372549f, 0.56078434f, 0.56078434f};
1076inline constexpr Color Color::ROYAL_BLUE{0.25490198f, 0.4117647f, 0.88235295f};
1077inline constexpr Color Color::SADDLE_BROWN{0.54509807f, 0.27058825f,
1078 0.07450981f};
1079inline constexpr Color Color::SALMON{0.98039216f, 0.5019608f, 0.44705883f};
1080inline constexpr Color Color::SANDY_BROWN{0.95686275f, 0.6431373f, 0.3764706f};
1081inline constexpr Color Color::SEA_GREEN{0.18039216f, 0.54509807f, 0.34117648f};
1082inline constexpr Color Color::SEASHELL{1.0f, 0.9607843f, 0.93333334f};
1083inline constexpr Color Color::SIENNA{0.627451f, 0.32156864f, 0.1764706f};
1084inline constexpr Color Color::SILVER{0.7529412f, 0.7529412f, 0.7529412f};
1085inline constexpr Color Color::SKY_BLUE{0.5294118f, 0.80784315f, 0.92156863f};
1086inline constexpr Color Color::SLATE_BLUE{0.41568628f, 0.3529412f, 0.8039216f};
1087inline constexpr Color Color::SLATE_GRAY{0.4392157f, 0.5019608f, 0.5647059f};
1088inline constexpr Color Color::SNOW{1.0f, 0.98039216f, 0.98039216f};
1089inline constexpr Color Color::SPRING_GREEN{0.0f, 1.0f, 0.49803922f};
1090inline constexpr Color Color::STEEL_BLUE{0.27450982f, 0.50980395f, 0.7058824f};
1091inline constexpr Color Color::TAN{0.8235294f, 0.7058824f, 0.54901963f};
1092inline constexpr Color Color::TEAL{0.0f, 0.5019608f, 0.5019608f};
1093inline constexpr Color Color::THISTLE{0.84705883f, 0.7490196f, 0.84705883f};
1094inline constexpr Color Color::TOMATO{1.0f, 0.3882353f, 0.2784314f};
1095inline constexpr Color Color::TURQUOISE{0.2509804f, 0.8784314f, 0.8156863f};
1096inline constexpr Color Color::VIOLET{0.93333334f, 0.50980395f, 0.93333334f};
1097inline constexpr Color Color::WHEAT{0.9607843f, 0.87058824f, 0.7019608f};
1098inline constexpr Color Color::WHITE{1.0f, 1.0f, 1.0f};
1099inline constexpr Color Color::WHITE_SMOKE{0.9607843f, 0.9607843f, 0.9607843f};
1100inline constexpr Color Color::YELLOW{1.0f, 1.0f, 0.0f};
1101inline constexpr Color Color::YELLOW_GREEN{0.6039216f, 0.8039216f, 0.19607843f};
1102
1103} // namespace wpi::util
Represents colors that can be used with Addressable LEDs.
Definition Color.hpp:42
static const Color LIGHT_CYAN
0xE0FFFF.
Definition Color.hpp:395
static const Color PINK
0xFFC0CB.
Definition Color.hpp:615
static const Color ALICE_BLUE
0xF0F8FF.
Definition Color.hpp:70
static const Color BURLYWOOD
0xDEB887.
Definition Color.hpp:130
static const Color PALE_VIOLET_RED
0xDB7093.
Definition Color.hpp:595
static const Color ROSY_BROWN
0xBC8F8F.
Definition Color.hpp:640
static const Color NAVAJO_WHITE
0xFFDEAD.
Definition Color.hpp:540
static const Color OLD_LACE
0xFDF5E6.
Definition Color.hpp:550
static const Color LIGHT_PINK
0xFFB6C1.
Definition Color.hpp:415
static const Color BLUE
0x0000FF.
Definition Color.hpp:115
static const Color DARK_RED
0x8B0000.
Definition Color.hpp:225
static const Color VIOLET
0xEE82EE.
Definition Color.hpp:740
static const Color PALE_GOLDENROD
0xEEE8AA.
Definition Color.hpp:580
static const Color MAGENTA
0xFF00FF.
Definition Color.hpp:465
static const Color PEACH_PUFF
0xFFDAB9.
Definition Color.hpp:605
static const Color SADDLE_BROWN
0x8B4513.
Definition Color.hpp:650
constexpr bool operator==(const Color &) const =default
static const Color MEDIUM_TURQUOISE
0x48D1CC.
Definition Color.hpp:510
static const Color INDIGO
0x4B0082.
Definition Color.hpp:350
static const Color OLIVE
0x808000.
Definition Color.hpp:555
static const Color FIREBRICK
0xB22222.
Definition Color.hpp:280
static const Color FIRST_BLUE
0x0066B3.
Definition Color.hpp:56
static const Color LIGHT_BLUE
0xADD8E6.
Definition Color.hpp:385
static const Color SILVER
0xC0C0C0.
Definition Color.hpp:680
static const Color GREEN
0x008000.
Definition Color.hpp:325
static const Color DODGER_BLUE
0x1E90FF.
Definition Color.hpp:275
static const Color BROWN
0xA52A2A.
Definition Color.hpp:125
static const Color PAPAYA_WHIP
0xFFEFD5.
Definition Color.hpp:600
static const Color WHEAT
0xF5DEB3.
Definition Color.hpp:745
static const Color LEMON_CHIFFON
0xFFFACD.
Definition Color.hpp:380
static const Color GHOST_WHITE
0xF8F8FF.
Definition Color.hpp:305
static const Color SLATE_GRAY
0x708090.
Definition Color.hpp:695
static const Color PERU
0xCD853F.
Definition Color.hpp:610
static const Color MEDIUM_SPRING_GREEN
0x00FA9A.
Definition Color.hpp:505
static const Color DARK_SEA_GREEN
0x8FBC8F.
Definition Color.hpp:235
static const Color LINEN
0xFAF0E6.
Definition Color.hpp:460
static const Color CADET_BLUE
0x5F9EA0.
Definition Color.hpp:135
static const Color TAN
0xD2B48C.
Definition Color.hpp:715
static const Color RED
0xFF0000.
Definition Color.hpp:635
static const Color DARK_KHAKI
0xBDB76B.
Definition Color.hpp:200
static const Color DEEP_SKY_BLUE
0x00BFFF.
Definition Color.hpp:265
static const Color CHARTREUSE
0x7FFF00.
Definition Color.hpp:140
static const Color MEDIUM_ORCHID
0xBA55D3.
Definition Color.hpp:485
static const Color INDIAN_RED
0xCD5C5C.
Definition Color.hpp:345
static const Color SKY_BLUE
0x87CEEB.
Definition Color.hpp:685
static const Color HOT_PINK
0xFF69B4.
Definition Color.hpp:340
static const Color TOMATO
0xFF6347.
Definition Color.hpp:730
static const Color LIME_GREEN
0x32CD32.
Definition Color.hpp:455
static const Color ANTIQUE_WHITE
0xFAEBD7.
Definition Color.hpp:75
static const Color PURPLE
0x800080.
Definition Color.hpp:630
static const Color CRIMSON
0xDC143C.
Definition Color.hpp:165
static const Color BEIGE
0xF5F5DC.
Definition Color.hpp:95
static const Color SEA_GREEN
0x2E8B57.
Definition Color.hpp:665
static const Color MOCCASIN
0xFFE4B5.
Definition Color.hpp:535
static const Color MAROON
0x800000.
Definition Color.hpp:470
static const Color HONEYDEW
0xF0FFF0.
Definition Color.hpp:335
static const Color DIM_GRAY
0x696969.
Definition Color.hpp:270
static const Color DARK_TURQUOISE
0x00CED1.
Definition Color.hpp:250
static const Color YELLOW
0xFFFF00.
Definition Color.hpp:760
static const Color GOLD
0xFFD700.
Definition Color.hpp:310
static const Color SNOW
0xFFFAFA.
Definition Color.hpp:700
static const Color LIGHT_GOLDENROD_YELLOW
0xFAFAD2.
Definition Color.hpp:400
static const Color LIGHT_STEEL_BLUE
0xB0C4DE.
Definition Color.hpp:440
static const Color OLIVE_DRAB
0x6B8E23.
Definition Color.hpp:560
static const Color ORCHID
0xDA70D6.
Definition Color.hpp:575
double green
Green component (0-1).
Definition Color.hpp:918
static const Color SLATE_BLUE
0x6A5ACD.
Definition Color.hpp:690
static constexpr Color FromString(std::string_view str)
Makes a Color from a string.
Definition Color.hpp:803
static const Color DARK_SLATE_GRAY
0x2F4F4F.
Definition Color.hpp:245
static const Color LIME
0x00FF00.
Definition Color.hpp:450
static const Color DARK_GRAY
0xA9A9A9.
Definition Color.hpp:190
static const Color DARK_SLATE_BLUE
0x483D8B.
Definition Color.hpp:240
static const Color SALMON
0xFA8072.
Definition Color.hpp:655
static const Color DENIM
0x1560BD.
Definition Color.hpp:51
static const Color MISTY_ROSE
0xFFE4E1.
Definition Color.hpp:530
static const Color DARK_VIOLET
0x9400D3.
Definition Color.hpp:255
static const Color TEAL
0x008080.
Definition Color.hpp:720
static const Color LIGHT_GREEN
0x90EE90.
Definition Color.hpp:410
static const Color CORNFLOWER_BLUE
0x6495ED.
Definition Color.hpp:155
static const Color PALE_TURQUOISE
0xAFEEEE.
Definition Color.hpp:590
static const Color CORAL
0xFF7F50.
Definition Color.hpp:150
static const Color KHAKI
0xF0E68C.
Definition Color.hpp:360
static const Color TURQUOISE
0x40E0D0.
Definition Color.hpp:735
static const Color IVORY
0xFFFFF0.
Definition Color.hpp:355
static const Color WHITE
0xFFFFFF.
Definition Color.hpp:750
static const Color DARK_MAGENTA
0x8B008B.
Definition Color.hpp:205
static const Color LAWN_GREEN
0x7CFC00.
Definition Color.hpp:375
static const Color AQUAMARINE
0x7FFFD4.
Definition Color.hpp:85
static const Color DARK_ORCHID
0x9932CC.
Definition Color.hpp:220
static const Color MEDIUM_SLATE_BLUE
0x7B68EE.
Definition Color.hpp:500
static const Color LIGHT_CORAL
0xF08080.
Definition Color.hpp:390
static const Color ORANGE_RED
0xFF4500.
Definition Color.hpp:570
static const Color THISTLE
0xD8BFD8.
Definition Color.hpp:725
static const Color LIGHT_SKY_BLUE
0x87CEFA.
Definition Color.hpp:430
static const Color FUCHSIA
0xFF00FF.
Definition Color.hpp:295
static const Color SPRING_GREEN
0x00FF7F.
Definition Color.hpp:705
static const Color FOREST_GREEN
0x228B22.
Definition Color.hpp:290
static constexpr Color FromHSV(int h, int s, int v)
Creates a Color from HSV values.
Definition Color.hpp:860
static const Color ROYAL_BLUE
0x4169E1.
Definition Color.hpp:645
static const Color SEASHELL
0xFFF5EE.
Definition Color.hpp:670
static const Color MEDIUM_PURPLE
0x9370DB.
Definition Color.hpp:490
static const Color DARK_OLIVE_GREEN
0x556B2F.
Definition Color.hpp:210
static const Color YELLOW_GREEN
0x9ACD32.
Definition Color.hpp:765
static const Color WHITE_SMOKE
0xF5F5F5.
Definition Color.hpp:755
static const Color CORNSILK
0xFFF8DC.
Definition Color.hpp:160
static const Color BLACK
0x000000.
Definition Color.hpp:105
static const Color LIGHT_GRAY
0xD3D3D3.
Definition Color.hpp:405
static const Color GREEN_YELLOW
0xADFF2F.
Definition Color.hpp:330
double red
Red component (0-1).
Definition Color.hpp:915
static const Color PLUM
0xDDA0DD.
Definition Color.hpp:620
static const Color LAVENDER_BLUSH
0xFFF0F5.
Definition Color.hpp:370
static const Color GRAY
0x808080.
Definition Color.hpp:320
static const Color DARK_BLUE
0x00008B.
Definition Color.hpp:175
static const Color AQUA
0x00FFFF.
Definition Color.hpp:80
static const Color SIENNA
0xA0522D.
Definition Color.hpp:675
constexpr Color(double r, double g, double b)
Constructs a Color from doubles (0-1).
Definition Color.hpp:779
constexpr auto HexString() const
Return this color represented as a hex string.
Definition Color.hpp:903
double blue
Blue component (0-1).
Definition Color.hpp:921
static const Color BLANCHED_ALMOND
0xFFEBCD.
Definition Color.hpp:110
static const Color LIGHT_SLATE_GRAY
0x778899.
Definition Color.hpp:435
static const Color DARK_ORANGE
0xFF8C00.
Definition Color.hpp:215
static const Color FLORAL_WHITE
0xFFFAF0.
Definition Color.hpp:285
static const Color LIGHT_SALMON
0xFFA07A.
Definition Color.hpp:420
static const Color DARK_GREEN
0x006400.
Definition Color.hpp:195
static const Color DARK_SALMON
0xE9967A.
Definition Color.hpp:230
static const Color MIDNIGHT_BLUE
0x191970.
Definition Color.hpp:520
constexpr Color()=default
Constructs a default color (black).
static const Color PALE_GREEN
0x98FB98.
Definition Color.hpp:585
static const Color BLUE_VIOLET
0x8A2BE2.
Definition Color.hpp:120
static const Color LIGHT_SEA_GREEN
0x20B2AA.
Definition Color.hpp:425
static const Color NAVY
0x000080.
Definition Color.hpp:545
static const Color GAINSBORO
0xDCDCDC.
Definition Color.hpp:300
static const Color SANDY_BROWN
0xF4A460.
Definition Color.hpp:660
static const Color STEEL_BLUE
0x4682B4.
Definition Color.hpp:710
static const Color DEEP_PINK
0xFF1493.
Definition Color.hpp:260
static const Color BISQUE
0xFFE4C4.
Definition Color.hpp:100
static const Color LAVENDER
0xE6E6FA.
Definition Color.hpp:365
static const Color MEDIUM_VIOLET_RED
0xC71585.
Definition Color.hpp:515
constexpr Color(int r, int g, int b)
Constructs a Color from ints (0-255).
Definition Color.hpp:791
static const Color CYAN
0x00FFFF.
Definition Color.hpp:170
static const Color MEDIUM_BLUE
0x0000CD.
Definition Color.hpp:480
static const Color POWDER_BLUE
0xB0E0E6.
Definition Color.hpp:625
static const Color DARK_GOLDENROD
0xB8860B.
Definition Color.hpp:185
static const Color MEDIUM_SEA_GREEN
0x3CB371.
Definition Color.hpp:495
static const Color ORANGE
0xFFA500.
Definition Color.hpp:565
static const Color MINTCREAM
0xF5FFFA.
Definition Color.hpp:525
static const Color FIRST_RED
0xED1C24.
Definition Color.hpp:61
static const Color CHOCOLATE
0xD2691E.
Definition Color.hpp:145
static const Color DARK_CYAN
0x008B8B.
Definition Color.hpp:180
static const Color GOLDENROD
0xDAA520.
Definition Color.hpp:315
static const Color AZURE
0xF0FFFF.
Definition Color.hpp:90
static const Color LIGHT_YELLOW
0xFFFFE0.
Definition Color.hpp:445
static const Color MEDIUM_AQUAMARINE
0x66CDAA.
Definition Color.hpp:475
These are wrappers over isa* function that allow them to be used in generic algorithms such as wpi::u...
Definition type_traits.hpp:71
constexpr double ceil_int(double x, double x_whole) noexcept
Definition Color.hpp:22
constexpr double ceil(double x) noexcept
Definition Color.hpp:26
Definition raw_os_ostream.hpp:19
Fixed length string (array of character) for compile time use.
Definition ct_string.hpp:29