WPILibC++ 2027.0.0-alpha-4
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 kDenim;
52
53 /**
54 * 0x0066B3.
55 */
56 static const Color kFirstBlue;
57
58 /**
59 * 0xED1C24.
60 */
61 static const Color kFirstRed;
62
63 /*
64 * Standard Colors
65 */
66
67 /**
68 * 0xF0F8FF.
69 */
70 static const Color kAliceBlue;
71
72 /**
73 * 0xFAEBD7.
74 */
75 static const Color kAntiqueWhite;
76
77 /**
78 * 0x00FFFF.
79 */
80 static const Color kAqua;
81
82 /**
83 * 0x7FFFD4.
84 */
85 static const Color kAquamarine;
86
87 /**
88 * 0xF0FFFF.
89 */
90 static const Color kAzure;
91
92 /**
93 * 0xF5F5DC.
94 */
95 static const Color kBeige;
96
97 /**
98 * 0xFFE4C4.
99 */
100 static const Color kBisque;
101
102 /**
103 * 0x000000.
104 */
105 static const Color kBlack;
106
107 /**
108 * 0xFFEBCD.
109 */
110 static const Color kBlanchedAlmond;
111
112 /**
113 * 0x0000FF.
114 */
115 static const Color kBlue;
116
117 /**
118 * 0x8A2BE2.
119 */
120 static const Color kBlueViolet;
121
122 /**
123 * 0xA52A2A.
124 */
125 static const Color kBrown;
126
127 /**
128 * 0xDEB887.
129 */
130 static const Color kBurlywood;
131
132 /**
133 * 0x5F9EA0.
134 */
135 static const Color kCadetBlue;
136
137 /**
138 * 0x7FFF00.
139 */
140 static const Color kChartreuse;
141
142 /**
143 * 0xD2691E.
144 */
145 static const Color kChocolate;
146
147 /**
148 * 0xFF7F50.
149 */
150 static const Color kCoral;
151
152 /**
153 * 0x6495ED.
154 */
155 static const Color kCornflowerBlue;
156
157 /**
158 * 0xFFF8DC.
159 */
160 static const Color kCornsilk;
161
162 /**
163 * 0xDC143C.
164 */
165 static const Color kCrimson;
166
167 /**
168 * 0x00FFFF.
169 */
170 static const Color kCyan;
171
172 /**
173 * 0x00008B.
174 */
175 static const Color kDarkBlue;
176
177 /**
178 * 0x008B8B.
179 */
180 static const Color kDarkCyan;
181
182 /**
183 * 0xB8860B.
184 */
185 static const Color kDarkGoldenrod;
186
187 /**
188 * 0xA9A9A9.
189 */
190 static const Color kDarkGray;
191
192 /**
193 * 0x006400.
194 */
195 static const Color kDarkGreen;
196
197 /**
198 * 0xBDB76B.
199 */
200 static const Color kDarkKhaki;
201
202 /**
203 * 0x8B008B.
204 */
205 static const Color kDarkMagenta;
206
207 /**
208 * 0x556B2F.
209 */
210 static const Color kDarkOliveGreen;
211
212 /**
213 * 0xFF8C00.
214 */
215 static const Color kDarkOrange;
216
217 /**
218 * 0x9932CC.
219 */
220 static const Color kDarkOrchid;
221
222 /**
223 * 0x8B0000.
224 */
225 static const Color kDarkRed;
226
227 /**
228 * 0xE9967A.
229 */
230 static const Color kDarkSalmon;
231
232 /**
233 * 0x8FBC8F.
234 */
235 static const Color kDarkSeaGreen;
236
237 /**
238 * 0x483D8B.
239 */
240 static const Color kDarkSlateBlue;
241
242 /**
243 * 0x2F4F4F.
244 */
245 static const Color kDarkSlateGray;
246
247 /**
248 * 0x00CED1.
249 */
250 static const Color kDarkTurquoise;
251
252 /**
253 * 0x9400D3.
254 */
255 static const Color kDarkViolet;
256
257 /**
258 * 0xFF1493.
259 */
260 static const Color kDeepPink;
261
262 /**
263 * 0x00BFFF.
264 */
265 static const Color kDeepSkyBlue;
266
267 /**
268 * 0x696969.
269 */
270 static const Color kDimGray;
271
272 /**
273 * 0x1E90FF.
274 */
275 static const Color kDodgerBlue;
276
277 /**
278 * 0xB22222.
279 */
280 static const Color kFirebrick;
281
282 /**
283 * 0xFFFAF0.
284 */
285 static const Color kFloralWhite;
286
287 /**
288 * 0x228B22.
289 */
290 static const Color kForestGreen;
291
292 /**
293 * 0xFF00FF.
294 */
295 static const Color kFuchsia;
296
297 /**
298 * 0xDCDCDC.
299 */
300 static const Color kGainsboro;
301
302 /**
303 * 0xF8F8FF.
304 */
305 static const Color kGhostWhite;
306
307 /**
308 * 0xFFD700.
309 */
310 static const Color kGold;
311
312 /**
313 * 0xDAA520.
314 */
315 static const Color kGoldenrod;
316
317 /**
318 * 0x808080.
319 */
320 static const Color kGray;
321
322 /**
323 * 0x008000.
324 */
325 static const Color kGreen;
326
327 /**
328 * 0xADFF2F.
329 */
330 static const Color kGreenYellow;
331
332 /**
333 * 0xF0FFF0.
334 */
335 static const Color kHoneydew;
336
337 /**
338 * 0xFF69B4.
339 */
340 static const Color kHotPink;
341
342 /**
343 * 0xCD5C5C.
344 */
345 static const Color kIndianRed;
346
347 /**
348 * 0x4B0082.
349 */
350 static const Color kIndigo;
351
352 /**
353 * 0xFFFFF0.
354 */
355 static const Color kIvory;
356
357 /**
358 * 0xF0E68C.
359 */
360 static const Color kKhaki;
361
362 /**
363 * 0xE6E6FA.
364 */
365 static const Color kLavender;
366
367 /**
368 * 0xFFF0F5.
369 */
370 static const Color kLavenderBlush;
371
372 /**
373 * 0x7CFC00.
374 */
375 static const Color kLawnGreen;
376
377 /**
378 * 0xFFFACD.
379 */
380 static const Color kLemonChiffon;
381
382 /**
383 * 0xADD8E6.
384 */
385 static const Color kLightBlue;
386
387 /**
388 * 0xF08080.
389 */
390 static const Color kLightCoral;
391
392 /**
393 * 0xE0FFFF.
394 */
395 static const Color kLightCyan;
396
397 /**
398 * 0xFAFAD2.
399 */
401
402 /**
403 * 0xD3D3D3.
404 */
405 static const Color kLightGray;
406
407 /**
408 * 0x90EE90.
409 */
410 static const Color kLightGreen;
411
412 /**
413 * 0xFFB6C1.
414 */
415 static const Color kLightPink;
416
417 /**
418 * 0xFFA07A.
419 */
420 static const Color kLightSalmon;
421
422 /**
423 * 0x20B2AA.
424 */
425 static const Color kLightSeaGreen;
426
427 /**
428 * 0x87CEFA.
429 */
430 static const Color kLightSkyBlue;
431
432 /**
433 * 0x778899.
434 */
435 static const Color kLightSlateGray;
436
437 /**
438 * 0xB0C4DE.
439 */
440 static const Color kLightSteelBlue;
441
442 /**
443 * 0xFFFFE0.
444 */
445 static const Color kLightYellow;
446
447 /**
448 * 0x00FF00.
449 */
450 static const Color kLime;
451
452 /**
453 * 0x32CD32.
454 */
455 static const Color kLimeGreen;
456
457 /**
458 * 0xFAF0E6.
459 */
460 static const Color kLinen;
461
462 /**
463 * 0xFF00FF.
464 */
465 static const Color kMagenta;
466
467 /**
468 * 0x800000.
469 */
470 static const Color kMaroon;
471
472 /**
473 * 0x66CDAA.
474 */
476
477 /**
478 * 0x0000CD.
479 */
480 static const Color kMediumBlue;
481
482 /**
483 * 0xBA55D3.
484 */
485 static const Color kMediumOrchid;
486
487 /**
488 * 0x9370DB.
489 */
490 static const Color kMediumPurple;
491
492 /**
493 * 0x3CB371.
494 */
495 static const Color kMediumSeaGreen;
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 kMidnightBlue;
521
522 /**
523 * 0xF5FFFA.
524 */
525 static const Color kMintcream;
526
527 /**
528 * 0xFFE4E1.
529 */
530 static const Color kMistyRose;
531
532 /**
533 * 0xFFE4B5.
534 */
535 static const Color kMoccasin;
536
537 /**
538 * 0xFFDEAD.
539 */
540 static const Color kNavajoWhite;
541
542 /**
543 * 0x000080.
544 */
545 static const Color kNavy;
546
547 /**
548 * 0xFDF5E6.
549 */
550 static const Color kOldLace;
551
552 /**
553 * 0x808000.
554 */
555 static const Color kOlive;
556
557 /**
558 * 0x6B8E23.
559 */
560 static const Color kOliveDrab;
561
562 /**
563 * 0xFFA500.
564 */
565 static const Color kOrange;
566
567 /**
568 * 0xFF4500.
569 */
570 static const Color kOrangeRed;
571
572 /**
573 * 0xDA70D6.
574 */
575 static const Color kOrchid;
576
577 /**
578 * 0xEEE8AA.
579 */
580 static const Color kPaleGoldenrod;
581
582 /**
583 * 0x98FB98.
584 */
585 static const Color kPaleGreen;
586
587 /**
588 * 0xAFEEEE.
589 */
590 static const Color kPaleTurquoise;
591
592 /**
593 * 0xDB7093.
594 */
595 static const Color kPaleVioletRed;
596
597 /**
598 * 0xFFEFD5.
599 */
600 static const Color kPapayaWhip;
601
602 /**
603 * 0xFFDAB9.
604 */
605 static const Color kPeachPuff;
606
607 /**
608 * 0xCD853F.
609 */
610 static const Color kPeru;
611
612 /**
613 * 0xFFC0CB.
614 */
615 static const Color kPink;
616
617 /**
618 * 0xDDA0DD.
619 */
620 static const Color kPlum;
621
622 /**
623 * 0xB0E0E6.
624 */
625 static const Color kPowderBlue;
626
627 /**
628 * 0x800080.
629 */
630 static const Color kPurple;
631
632 /**
633 * 0xFF0000.
634 */
635 static const Color kRed;
636
637 /**
638 * 0xBC8F8F.
639 */
640 static const Color kRosyBrown;
641
642 /**
643 * 0x4169E1.
644 */
645 static const Color kRoyalBlue;
646
647 /**
648 * 0x8B4513.
649 */
650 static const Color kSaddleBrown;
651
652 /**
653 * 0xFA8072.
654 */
655 static const Color kSalmon;
656
657 /**
658 * 0xF4A460.
659 */
660 static const Color kSandyBrown;
661
662 /**
663 * 0x2E8B57.
664 */
665 static const Color kSeaGreen;
666
667 /**
668 * 0xFFF5EE.
669 */
670 static const Color kSeashell;
671
672 /**
673 * 0xA0522D.
674 */
675 static const Color kSienna;
676
677 /**
678 * 0xC0C0C0.
679 */
680 static const Color kSilver;
681
682 /**
683 * 0x87CEEB.
684 */
685 static const Color kSkyBlue;
686
687 /**
688 * 0x6A5ACD.
689 */
690 static const Color kSlateBlue;
691
692 /**
693 * 0x708090.
694 */
695 static const Color kSlateGray;
696
697 /**
698 * 0xFFFAFA.
699 */
700 static const Color kSnow;
701
702 /**
703 * 0x00FF7F.
704 */
705 static const Color kSpringGreen;
706
707 /**
708 * 0x4682B4.
709 */
710 static const Color kSteelBlue;
711
712 /**
713 * 0xD2B48C.
714 */
715 static const Color kTan;
716
717 /**
718 * 0x008080.
719 */
720 static const Color kTeal;
721
722 /**
723 * 0xD8BFD8.
724 */
725 static const Color kThistle;
726
727 /**
728 * 0xFF6347.
729 */
730 static const Color kTomato;
731
732 /**
733 * 0x40E0D0.
734 */
735 static const Color kTurquoise;
736
737 /**
738 * 0xEE82EE.
739 */
740 static const Color kViolet;
741
742 /**
743 * 0xF5DEB3.
744 */
745 static const Color kWheat;
746
747 /**
748 * 0xFFFFFF.
749 */
750 static const Color kWhite;
751
752 /**
753 * 0xF5F5F5.
754 */
755 static const Color kWhiteSmoke;
756
757 /**
758 * 0xFFFF00.
759 */
760 static const Color kYellow;
761
762 /**
763 * 0x9ACD32.
764 */
765 static const Color kYellowGreen;
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) >> 8;
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::kDenim{0.0823529412, 0.376470589, 0.7411764706};
933inline constexpr Color Color::kFirstBlue{0.0, 0.4, 0.7019607844};
934inline constexpr Color Color::kFirstRed{0.9294117648, 0.1098039216,
935 0.1411764706};
936
937/*
938 * Standard Colors
939 */
940inline constexpr Color Color::kAliceBlue{0.9411765f, 0.972549f, 1.0f};
941inline constexpr Color Color::kAntiqueWhite{0.98039216f, 0.92156863f,
942 0.84313726f};
943inline constexpr Color Color::kAqua{0.0f, 1.0f, 1.0f};
944inline constexpr Color Color::kAquamarine{0.49803922f, 1.0f, 0.83137256f};
945inline constexpr Color Color::kAzure{0.9411765f, 1.0f, 1.0f};
946inline constexpr Color Color::kBeige{0.9607843f, 0.9607843f, 0.8627451f};
947inline constexpr Color Color::kBisque{1.0f, 0.89411765f, 0.76862746f};
948inline constexpr Color Color::kBlack{0.0f, 0.0f, 0.0f};
949inline constexpr Color Color::kBlanchedAlmond{1.0f, 0.92156863f, 0.8039216f};
950inline constexpr Color Color::kBlue{0.0f, 0.0f, 1.0f};
951inline constexpr Color Color::kBlueViolet{0.5411765f, 0.16862746f, 0.8862745f};
952inline constexpr Color Color::kBrown{0.64705884f, 0.16470589f, 0.16470589f};
953inline constexpr Color Color::kBurlywood{0.87058824f, 0.72156864f, 0.5294118f};
954inline constexpr Color Color::kCadetBlue{0.37254903f, 0.61960787f, 0.627451f};
955inline constexpr Color Color::kChartreuse{0.49803922f, 1.0f, 0.0f};
956inline constexpr Color Color::kChocolate{0.8235294f, 0.4117647f, 0.11764706f};
957inline constexpr Color Color::kCoral{1.0f, 0.49803922f, 0.3137255f};
958inline constexpr Color Color::kCornflowerBlue{0.39215687f, 0.58431375f,
959 0.92941177f};
960inline constexpr Color Color::kCornsilk{1.0f, 0.972549f, 0.8627451f};
961inline constexpr Color Color::kCrimson{0.8627451f, 0.078431375f, 0.23529412f};
962inline constexpr Color Color::kCyan{0.0f, 1.0f, 1.0f};
963inline constexpr Color Color::kDarkBlue{0.0f, 0.0f, 0.54509807f};
964inline constexpr Color Color::kDarkCyan{0.0f, 0.54509807f, 0.54509807f};
965inline constexpr Color Color::kDarkGoldenrod{0.72156864f, 0.5254902f,
966 0.043137256f};
967inline constexpr Color Color::kDarkGray{0.6627451f, 0.6627451f, 0.6627451f};
968inline constexpr Color Color::kDarkGreen{0.0f, 0.39215687f, 0.0f};
969inline constexpr Color Color::kDarkKhaki{0.7411765f, 0.7176471f, 0.41960785f};
970inline constexpr Color Color::kDarkMagenta{0.54509807f, 0.0f, 0.54509807f};
971inline constexpr Color Color::kDarkOliveGreen{0.33333334f, 0.41960785f,
972 0.18431373f};
973inline constexpr Color Color::kDarkOrange{1.0f, 0.54901963f, 0.0f};
974inline constexpr Color Color::kDarkOrchid{0.6f, 0.19607843f, 0.8f};
975inline constexpr Color Color::kDarkRed{0.54509807f, 0.0f, 0.0f};
976inline constexpr Color Color::kDarkSalmon{0.9137255f, 0.5882353f, 0.47843137f};
977inline constexpr Color Color::kDarkSeaGreen{0.56078434f, 0.7372549f,
978 0.56078434f};
979inline constexpr Color Color::kDarkSlateBlue{0.28235295f, 0.23921569f,
980 0.54509807f};
981inline constexpr Color Color::kDarkSlateGray{0.18431373f, 0.30980393f,
982 0.30980393f};
983inline constexpr Color Color::kDarkTurquoise{0.0f, 0.80784315f, 0.81960785f};
984inline constexpr Color Color::kDarkViolet{0.5803922f, 0.0f, 0.827451f};
985inline constexpr Color Color::kDeepPink{1.0f, 0.078431375f, 0.5764706f};
986inline constexpr Color Color::kDeepSkyBlue{0.0f, 0.7490196f, 1.0f};
987inline constexpr Color Color::kDimGray{0.4117647f, 0.4117647f, 0.4117647f};
988inline constexpr Color Color::kDodgerBlue{0.11764706f, 0.5647059f, 1.0f};
989inline constexpr Color Color::kFirebrick{0.69803923f, 0.13333334f, 0.13333334f};
990inline constexpr Color Color::kFloralWhite{1.0f, 0.98039216f, 0.9411765f};
991inline constexpr Color Color::kForestGreen{0.13333334f, 0.54509807f,
992 0.13333334f};
993inline constexpr Color Color::kFuchsia{1.0f, 0.0f, 1.0f};
994inline constexpr Color Color::kGainsboro{0.8627451f, 0.8627451f, 0.8627451f};
995inline constexpr Color Color::kGhostWhite{0.972549f, 0.972549f, 1.0f};
996inline constexpr Color Color::kGold{1.0f, 0.84313726f, 0.0f};
997inline constexpr Color Color::kGoldenrod{0.85490197f, 0.64705884f, 0.1254902f};
998inline constexpr Color Color::kGray{0.5019608f, 0.5019608f, 0.5019608f};
999inline constexpr Color Color::kGreen{0.0f, 0.5019608f, 0.0f};
1000inline constexpr Color Color::kGreenYellow{0.6784314f, 1.0f, 0.18431373f};
1001inline constexpr Color Color::kHoneydew{0.9411765f, 1.0f, 0.9411765f};
1002inline constexpr Color Color::kHotPink{1.0f, 0.4117647f, 0.7058824f};
1003inline constexpr Color Color::kIndianRed{0.8039216f, 0.36078432f, 0.36078432f};
1004inline constexpr Color Color::kIndigo{0.29411766f, 0.0f, 0.50980395f};
1005inline constexpr Color Color::kIvory{1.0f, 1.0f, 0.9411765f};
1006inline constexpr Color Color::kKhaki{0.9411765f, 0.9019608f, 0.54901963f};
1007inline constexpr Color Color::kLavender{0.9019608f, 0.9019608f, 0.98039216f};
1008inline constexpr Color Color::kLavenderBlush{1.0f, 0.9411765f, 0.9607843f};
1009inline constexpr Color Color::kLawnGreen{0.4862745f, 0.9882353f, 0.0f};
1010inline constexpr Color Color::kLemonChiffon{1.0f, 0.98039216f, 0.8039216f};
1011inline constexpr Color Color::kLightBlue{0.6784314f, 0.84705883f, 0.9019608f};
1012inline constexpr Color Color::kLightCoral{0.9411765f, 0.5019608f, 0.5019608f};
1013inline constexpr Color Color::kLightCyan{0.8784314f, 1.0f, 1.0f};
1014inline constexpr Color Color::kLightGoldenrodYellow{0.98039216f, 0.98039216f,
1015 0.8235294f};
1016inline constexpr Color Color::kLightGray{0.827451f, 0.827451f, 0.827451f};
1017inline constexpr Color Color::kLightGreen{0.5647059f, 0.93333334f, 0.5647059f};
1018inline constexpr Color Color::kLightPink{1.0f, 0.7137255f, 0.75686276f};
1019inline constexpr Color Color::kLightSalmon{1.0f, 0.627451f, 0.47843137f};
1020inline constexpr Color Color::kLightSeaGreen{0.1254902f, 0.69803923f,
1021 0.6666667f};
1022inline constexpr Color Color::kLightSkyBlue{0.5294118f, 0.80784315f,
1023 0.98039216f};
1024inline constexpr Color Color::kLightSlateGray{0.46666667f, 0.53333336f, 0.6f};
1025inline constexpr Color Color::kLightSteelBlue{0.6901961f, 0.76862746f,
1026 0.87058824f};
1027inline constexpr Color Color::kLightYellow{1.0f, 1.0f, 0.8784314f};
1028inline constexpr Color Color::kLime{0.0f, 1.0f, 0.0f};
1029inline constexpr Color Color::kLimeGreen{0.19607843f, 0.8039216f, 0.19607843f};
1030inline constexpr Color Color::kLinen{0.98039216f, 0.9411765f, 0.9019608f};
1031inline constexpr Color Color::kMagenta{1.0f, 0.0f, 1.0f};
1032inline constexpr Color Color::kMaroon{0.5019608f, 0.0f, 0.0f};
1033inline constexpr Color Color::kMediumAquamarine{0.4f, 0.8039216f, 0.6666667f};
1034inline constexpr Color Color::kMediumBlue{0.0f, 0.0f, 0.8039216f};
1035inline constexpr Color Color::kMediumOrchid{0.7294118f, 0.33333334f, 0.827451f};
1036inline constexpr Color Color::kMediumPurple{0.5764706f, 0.4392157f,
1037 0.85882354f};
1038inline constexpr Color Color::kMediumSeaGreen{0.23529412f, 0.7019608f,
1039 0.44313726f};
1040inline constexpr Color Color::kMediumSlateBlue{0.48235294f, 0.40784314f,
1041 0.93333334f};
1042inline constexpr Color Color::kMediumSpringGreen{0.0f, 0.98039216f, 0.6039216f};
1043inline constexpr Color Color::kMediumTurquoise{0.28235295f, 0.81960785f, 0.8f};
1044inline constexpr Color Color::kMediumVioletRed{0.78039217f, 0.08235294f,
1045 0.52156866f};
1046inline constexpr Color Color::kMidnightBlue{0.09803922f, 0.09803922f,
1047 0.4392157f};
1048inline constexpr Color Color::kMintcream{0.9607843f, 1.0f, 0.98039216f};
1049inline constexpr Color Color::kMistyRose{1.0f, 0.89411765f, 0.88235295f};
1050inline constexpr Color Color::kMoccasin{1.0f, 0.89411765f, 0.70980394f};
1051inline constexpr Color Color::kNavajoWhite{1.0f, 0.87058824f, 0.6784314f};
1052inline constexpr Color Color::kNavy{0.0f, 0.0f, 0.5019608f};
1053inline constexpr Color Color::kOldLace{0.99215686f, 0.9607843f, 0.9019608f};
1054inline constexpr Color Color::kOlive{0.5019608f, 0.5019608f, 0.0f};
1055inline constexpr Color Color::kOliveDrab{0.41960785f, 0.5568628f, 0.13725491f};
1056inline constexpr Color Color::kOrange{1.0f, 0.64705884f, 0.0f};
1057inline constexpr Color Color::kOrangeRed{1.0f, 0.27058825f, 0.0f};
1058inline constexpr Color Color::kOrchid{0.85490197f, 0.4392157f, 0.8392157f};
1059inline constexpr Color Color::kPaleGoldenrod{0.93333334f, 0.9098039f,
1060 0.6666667f};
1061inline constexpr Color Color::kPaleGreen{0.59607846f, 0.9843137f, 0.59607846f};
1062inline constexpr Color Color::kPaleTurquoise{0.6862745f, 0.93333334f,
1063 0.93333334f};
1064inline constexpr Color Color::kPaleVioletRed{0.85882354f, 0.4392157f,
1065 0.5764706f};
1066inline constexpr Color Color::kPapayaWhip{1.0f, 0.9372549f, 0.8352941f};
1067inline constexpr Color Color::kPeachPuff{1.0f, 0.85490197f, 0.7254902f};
1068inline constexpr Color Color::kPeru{0.8039216f, 0.52156866f, 0.24705882f};
1069inline constexpr Color Color::kPink{1.0f, 0.7529412f, 0.79607844f};
1070inline constexpr Color Color::kPlum{0.8666667f, 0.627451f, 0.8666667f};
1071inline constexpr Color Color::kPowderBlue{0.6901961f, 0.8784314f, 0.9019608f};
1072inline constexpr Color Color::kPurple{0.5019608f, 0.0f, 0.5019608f};
1073inline constexpr Color Color::kRed{1.0f, 0.0f, 0.0f};
1074inline constexpr Color Color::kRosyBrown{0.7372549f, 0.56078434f, 0.56078434f};
1075inline constexpr Color Color::kRoyalBlue{0.25490198f, 0.4117647f, 0.88235295f};
1076inline constexpr Color Color::kSaddleBrown{0.54509807f, 0.27058825f,
1077 0.07450981f};
1078inline constexpr Color Color::kSalmon{0.98039216f, 0.5019608f, 0.44705883f};
1079inline constexpr Color Color::kSandyBrown{0.95686275f, 0.6431373f, 0.3764706f};
1080inline constexpr Color Color::kSeaGreen{0.18039216f, 0.54509807f, 0.34117648f};
1081inline constexpr Color Color::kSeashell{1.0f, 0.9607843f, 0.93333334f};
1082inline constexpr Color Color::kSienna{0.627451f, 0.32156864f, 0.1764706f};
1083inline constexpr Color Color::kSilver{0.7529412f, 0.7529412f, 0.7529412f};
1084inline constexpr Color Color::kSkyBlue{0.5294118f, 0.80784315f, 0.92156863f};
1085inline constexpr Color Color::kSlateBlue{0.41568628f, 0.3529412f, 0.8039216f};
1086inline constexpr Color Color::kSlateGray{0.4392157f, 0.5019608f, 0.5647059f};
1087inline constexpr Color Color::kSnow{1.0f, 0.98039216f, 0.98039216f};
1088inline constexpr Color Color::kSpringGreen{0.0f, 1.0f, 0.49803922f};
1089inline constexpr Color Color::kSteelBlue{0.27450982f, 0.50980395f, 0.7058824f};
1090inline constexpr Color Color::kTan{0.8235294f, 0.7058824f, 0.54901963f};
1091inline constexpr Color Color::kTeal{0.0f, 0.5019608f, 0.5019608f};
1092inline constexpr Color Color::kThistle{0.84705883f, 0.7490196f, 0.84705883f};
1093inline constexpr Color Color::kTomato{1.0f, 0.3882353f, 0.2784314f};
1094inline constexpr Color Color::kTurquoise{0.2509804f, 0.8784314f, 0.8156863f};
1095inline constexpr Color Color::kViolet{0.93333334f, 0.50980395f, 0.93333334f};
1096inline constexpr Color Color::kWheat{0.9607843f, 0.87058824f, 0.7019608f};
1097inline constexpr Color Color::kWhite{1.0f, 1.0f, 1.0f};
1098inline constexpr Color Color::kWhiteSmoke{0.9607843f, 0.9607843f, 0.9607843f};
1099inline constexpr Color Color::kYellow{1.0f, 1.0f, 0.0f};
1100inline constexpr Color Color::kYellowGreen{0.6039216f, 0.8039216f, 0.19607843f};
1101
1102} // namespace wpi::util
Represents colors that can be used with Addressable LEDs.
Definition Color.hpp:42
static const Color kLemonChiffon
0xFFFACD.
Definition Color.hpp:380
static const Color kBlueViolet
0x8A2BE2.
Definition Color.hpp:120
static const Color kMediumSpringGreen
0x00FA9A.
Definition Color.hpp:505
static const Color kAquamarine
0x7FFFD4.
Definition Color.hpp:85
static const Color kLightSkyBlue
0x87CEFA.
Definition Color.hpp:430
static const Color kTurquoise
0x40E0D0.
Definition Color.hpp:735
static const Color kDarkViolet
0x9400D3.
Definition Color.hpp:255
static const Color kMagenta
0xFF00FF.
Definition Color.hpp:465
static const Color kLavenderBlush
0xFFF0F5.
Definition Color.hpp:370
static const Color kGold
0xFFD700.
Definition Color.hpp:310
static const Color kSienna
0xA0522D.
Definition Color.hpp:675
static const Color kCornsilk
0xFFF8DC.
Definition Color.hpp:160
static const Color kLightSteelBlue
0xB0C4DE.
Definition Color.hpp:440
static const Color kBurlywood
0xDEB887.
Definition Color.hpp:130
static const Color kLightCoral
0xF08080.
Definition Color.hpp:390
static const Color kPaleGoldenrod
0xEEE8AA.
Definition Color.hpp:580
static const Color kLightBlue
0xADD8E6.
Definition Color.hpp:385
static const Color kMediumOrchid
0xBA55D3.
Definition Color.hpp:485
static const Color kLime
0x00FF00.
Definition Color.hpp:450
static const Color kSeashell
0xFFF5EE.
Definition Color.hpp:670
static const Color kSkyBlue
0x87CEEB.
Definition Color.hpp:685
static const Color kCadetBlue
0x5F9EA0.
Definition Color.hpp:135
static const Color kBeige
0xF5F5DC.
Definition Color.hpp:95
static const Color kDeepPink
0xFF1493.
Definition Color.hpp:260
constexpr bool operator==(const Color &) const =default
static const Color kIvory
0xFFFFF0.
Definition Color.hpp:355
static const Color kLightPink
0xFFB6C1.
Definition Color.hpp:415
static const Color kLightYellow
0xFFFFE0.
Definition Color.hpp:445
static const Color kMidnightBlue
0x191970.
Definition Color.hpp:520
static const Color kOliveDrab
0x6B8E23.
Definition Color.hpp:560
static const Color kBisque
0xFFE4C4.
Definition Color.hpp:100
static const Color kDarkSeaGreen
0x8FBC8F.
Definition Color.hpp:235
static const Color kLightGreen
0x90EE90.
Definition Color.hpp:410
static const Color kPaleVioletRed
0xDB7093.
Definition Color.hpp:595
static const Color kLightSeaGreen
0x20B2AA.
Definition Color.hpp:425
static const Color kCoral
0xFF7F50.
Definition Color.hpp:150
static const Color kSaddleBrown
0x8B4513.
Definition Color.hpp:650
static const Color kGreen
0x008000.
Definition Color.hpp:325
static const Color kRed
0xFF0000.
Definition Color.hpp:635
static const Color kAzure
0xF0FFFF.
Definition Color.hpp:90
static const Color kTeal
0x008080.
Definition Color.hpp:720
static const Color kDimGray
0x696969.
Definition Color.hpp:270
static const Color kLightSlateGray
0x778899.
Definition Color.hpp:435
static const Color kFirstBlue
0x0066B3.
Definition Color.hpp:56
static const Color kDarkOrange
0xFF8C00.
Definition Color.hpp:215
static const Color kLawnGreen
0x7CFC00.
Definition Color.hpp:375
static const Color kBrown
0xA52A2A.
Definition Color.hpp:125
static const Color kGreenYellow
0xADFF2F.
Definition Color.hpp:330
static const Color kMediumPurple
0x9370DB.
Definition Color.hpp:490
static const Color kDodgerBlue
0x1E90FF.
Definition Color.hpp:275
static const Color kLightSalmon
0xFFA07A.
Definition Color.hpp:420
static const Color kHoneydew
0xF0FFF0.
Definition Color.hpp:335
static const Color kOlive
0x808000.
Definition Color.hpp:555
static const Color kGainsboro
0xDCDCDC.
Definition Color.hpp:300
static const Color kCornflowerBlue
0x6495ED.
Definition Color.hpp:155
static const Color kFuchsia
0xFF00FF.
Definition Color.hpp:295
static const Color kSlateGray
0x708090.
Definition Color.hpp:695
static const Color kDarkCyan
0x008B8B.
Definition Color.hpp:180
static const Color kIndigo
0x4B0082.
Definition Color.hpp:350
static const Color kChartreuse
0x7FFF00.
Definition Color.hpp:140
static const Color kDarkGreen
0x006400.
Definition Color.hpp:195
static const Color kChocolate
0xD2691E.
Definition Color.hpp:145
static const Color kDarkRed
0x8B0000.
Definition Color.hpp:225
static const Color kPeachPuff
0xFFDAB9.
Definition Color.hpp:605
static const Color kMediumTurquoise
0x48D1CC.
Definition Color.hpp:510
static const Color kHotPink
0xFF69B4.
Definition Color.hpp:340
static const Color kDarkGoldenrod
0xB8860B.
Definition Color.hpp:185
static const Color kDarkGray
0xA9A9A9.
Definition Color.hpp:190
double green
Green component (0-1).
Definition Color.hpp:918
static const Color kSteelBlue
0x4682B4.
Definition Color.hpp:710
static constexpr Color FromString(std::string_view str)
Makes a Color from a string.
Definition Color.hpp:803
static const Color kIndianRed
0xCD5C5C.
Definition Color.hpp:345
static const Color kPapayaWhip
0xFFEFD5.
Definition Color.hpp:600
static const Color kNavajoWhite
0xFFDEAD.
Definition Color.hpp:540
static const Color kDarkKhaki
0xBDB76B.
Definition Color.hpp:200
static const Color kOrange
0xFFA500.
Definition Color.hpp:565
static const Color kOrangeRed
0xFF4500.
Definition Color.hpp:570
static const Color kSandyBrown
0xF4A460.
Definition Color.hpp:660
static const Color kPlum
0xDDA0DD.
Definition Color.hpp:620
static const Color kPeru
0xCD853F.
Definition Color.hpp:610
static const Color kMaroon
0x800000.
Definition Color.hpp:470
static const Color kWhite
0xFFFFFF.
Definition Color.hpp:750
static const Color kDarkOrchid
0x9932CC.
Definition Color.hpp:220
static const Color kOldLace
0xFDF5E6.
Definition Color.hpp:550
static const Color kYellow
0xFFFF00.
Definition Color.hpp:760
static const Color kKhaki
0xF0E68C.
Definition Color.hpp:360
static const Color kAqua
0x00FFFF.
Definition Color.hpp:80
static const Color kPink
0xFFC0CB.
Definition Color.hpp:615
static const Color kMediumSlateBlue
0x7B68EE.
Definition Color.hpp:500
static const Color kAntiqueWhite
0xFAEBD7.
Definition Color.hpp:75
static const Color kDarkBlue
0x00008B.
Definition Color.hpp:175
static constexpr Color FromHSV(int h, int s, int v)
Creates a Color from HSV values.
Definition Color.hpp:860
static const Color kForestGreen
0x228B22.
Definition Color.hpp:290
static const Color kDarkOliveGreen
0x556B2F.
Definition Color.hpp:210
static const Color kLightGoldenrodYellow
0xFAFAD2.
Definition Color.hpp:400
static const Color kTan
0xD2B48C.
Definition Color.hpp:715
static const Color kThistle
0xD8BFD8.
Definition Color.hpp:725
static const Color kMintcream
0xF5FFFA.
Definition Color.hpp:525
static const Color kMediumSeaGreen
0x3CB371.
Definition Color.hpp:495
static const Color kAliceBlue
0xF0F8FF.
Definition Color.hpp:70
static const Color kMediumVioletRed
0xC71585.
Definition Color.hpp:515
static const Color kPaleTurquoise
0xAFEEEE.
Definition Color.hpp:590
double red
Red component (0-1).
Definition Color.hpp:915
static const Color kBlanchedAlmond
0xFFEBCD.
Definition Color.hpp:110
static const Color kLinen
0xFAF0E6.
Definition Color.hpp:460
static const Color kDeepSkyBlue
0x00BFFF.
Definition Color.hpp:265
static const Color kDarkSalmon
0xE9967A.
Definition Color.hpp:230
static const Color kDarkSlateBlue
0x483D8B.
Definition Color.hpp:240
static const Color kSeaGreen
0x2E8B57.
Definition Color.hpp:665
constexpr Color(double r, double g, double b)
Constructs a Color from doubles (0-1).
Definition Color.hpp:779
static const Color kFirebrick
0xB22222.
Definition Color.hpp:280
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 kDarkTurquoise
0x00CED1.
Definition Color.hpp:250
static const Color kNavy
0x000080.
Definition Color.hpp:545
static const Color kSalmon
0xFA8072.
Definition Color.hpp:655
static const Color kLimeGreen
0x32CD32.
Definition Color.hpp:455
static const Color kWheat
0xF5DEB3.
Definition Color.hpp:745
static const Color kDenim
0x1560BD.
Definition Color.hpp:51
static const Color kFirstRed
0xED1C24.
Definition Color.hpp:61
static const Color kLavender
0xE6E6FA.
Definition Color.hpp:365
static const Color kYellowGreen
0x9ACD32.
Definition Color.hpp:765
static const Color kPowderBlue
0xB0E0E6.
Definition Color.hpp:625
constexpr Color()=default
Constructs a default color (black).
static const Color kDarkSlateGray
0x2F4F4F.
Definition Color.hpp:245
static const Color kPurple
0x800080.
Definition Color.hpp:630
static const Color kOrchid
0xDA70D6.
Definition Color.hpp:575
static const Color kBlack
0x000000.
Definition Color.hpp:105
static const Color kCyan
0x00FFFF.
Definition Color.hpp:170
static const Color kSnow
0xFFFAFA.
Definition Color.hpp:700
static const Color kGray
0x808080.
Definition Color.hpp:320
static const Color kRosyBrown
0xBC8F8F.
Definition Color.hpp:640
static const Color kGoldenrod
0xDAA520.
Definition Color.hpp:315
static const Color kLightCyan
0xE0FFFF.
Definition Color.hpp:395
static const Color kSilver
0xC0C0C0.
Definition Color.hpp:680
static const Color kMistyRose
0xFFE4E1.
Definition Color.hpp:530
static const Color kCrimson
0xDC143C.
Definition Color.hpp:165
static const Color kBlue
0x0000FF.
Definition Color.hpp:115
static const Color kMoccasin
0xFFE4B5.
Definition Color.hpp:535
static const Color kPaleGreen
0x98FB98.
Definition Color.hpp:585
static const Color kSlateBlue
0x6A5ACD.
Definition Color.hpp:690
static const Color kRoyalBlue
0x4169E1.
Definition Color.hpp:645
static const Color kDarkMagenta
0x8B008B.
Definition Color.hpp:205
static const Color kGhostWhite
0xF8F8FF.
Definition Color.hpp:305
static const Color kMediumBlue
0x0000CD.
Definition Color.hpp:480
constexpr Color(int r, int g, int b)
Constructs a Color from ints (0-255).
Definition Color.hpp:791
static const Color kSpringGreen
0x00FF7F.
Definition Color.hpp:705
static const Color kFloralWhite
0xFFFAF0.
Definition Color.hpp:285
static const Color kViolet
0xEE82EE.
Definition Color.hpp:740
static const Color kTomato
0xFF6347.
Definition Color.hpp:730
static const Color kLightGray
0xD3D3D3.
Definition Color.hpp:405
static const Color kWhiteSmoke
0xF5F5F5.
Definition Color.hpp:755
static const Color kMediumAquamarine
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