/
color.py
1112 lines (868 loc) · 26.3 KB
/
color.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
try:
basestring # type: ignore
except NameError:
basestring = str
import colorsys
import re
from compas.colors.html_colors import HTML_TO_RGB255
from compas.data import Data
BASE16 = "0123456789abcdef"
try:
HEX_DEC = {v: int(v, base=16) for v in [x + y for x in BASE16 for y in BASE16]}
except Exception:
HEX_DEC = {v: int(v, 16) for v in [x + y for x in BASE16 for y in BASE16]}
class ColorError(Exception):
"""Raise if color input is not a color."""
class Color(Data):
"""Class for working with colors.
Parameters
----------
red : float
The red component in the range ``[0.0, 1.0]``.
green : float
The green component in the range of ``[0.0, 1.0]``.
blue : float
The blue component in the range of ``[0.0, 1.0]``.
alpha : float, optional
Transparency setting.
If ``alpha = 0.0``, the color is fully transparent.
If ``alpha = 1.0``, the color is fully opaque.
name : str, optional
The name of the color.
Attributes
----------
r : float
Red component of the color in RGB1 color space.
g : float
Green component of the color in RGB1 color space.
b : float
Blue component of the color in RGB1 color space.
a : float
Transparency in RGB1 color space.
rgb : tuple[float, float, float]
RGB1 color tuple, with components in the range ``[0.0, 1.0]``.
rgba : tuple[float, float, float, float]
RGBA1 color tuple (including alpha), with components in the range ``[0.0, 1.0]``.
rgb255 : tuple[int, int, int]
RGB255 color tuple, with components in the range ``[0, 255]``.
rgba255 : tuple[int, int, int, int]
RGBA255 color tuple (including alpha), with components in the range ``[0, 255]``.
hex : str
Hexadecimal color string.
hls : tuple[float, float, float]
Hue, Lightness, Saturation.
hsv : tuple[float, float, float]
Hue, Saturation, Value / Brightness.
lightness : float
How much white the color appears to contain.
This is the "Lightness" in HLS.
Making a color "lighter" is like adding more white.
brightness : float
How well-lit the color appears to be.
This is the "Value" in HSV.
Making a color "brighter" is like shining a stronger light on it, or illuminating it better.
yuv : tuple[float, float, float]
Luma and chroma components, with chroma defined by the blue and red projections.
luma : float
The brightness of a yuv signal.
chroma : tuple[float, float]
The color of a yuv signal.
"How different from a grey of the same lightness the color appears to be."
luminance : float
The amount of light that passes through, is emitted from, or is reflected from a particular area.
Here, it expresses the preceived brightness of the color.
Note that this is not the same as the "Lightness" of HLS or the "Value/Brightness" of HSV.
saturation : float
The perceived freedom of whiteness.
is_light : bool
If True, the color is considered light.
Examples
--------
By default, this class will create a color with the RGB components in the range ``[0.0, 1.0]``.
>>> Color(1, 0, 0)
Color(1.0, 0.0, 0.0, alpha=1.0)
Attempting to create a color with components outside of the range ``[0.0, 1.0]`` will raise a ``ValueError``.
>>> Color(255, 0, 0)
Traceback (most recent call last):
...
ValueError: Components of an RGBA color should be in the range 0-1.
To create a color with components in the range ``[0, 255]``, use the :meth:`from_rgb255` constructor.
>>> Color.from_rgb255(255, 0, 0)
Color(1.0, 0.0, 0.0, alpha=1.0)
Similarly, other constructors are available to create colors from other color spaces.
>>> color = Color.from_hls(0.0, 0.5, 1.0)
>>> color = Color.from_hsv(0.0, 1.0, 1.0)
>>> color = Color.from_yiq(0.0, 0.0, 0.0)
>>> color = Color.from_yuv(0.0, 0.0, 0.0)
Or, to construct specific colors, for example, ...
>>> color = Color.red()
>>> color = Color.magenta()
>>> color = Color.lime()
>>> color = Color.navy()
>>> color = Color.olive()
Colors can be modified through inversion, saturation/desaturation, and lightening/darkening.
>>> color = Color.red()
>>> color.desaturated(25)
Color(0.875, 0.125, 0.125, alpha=1.0)
>>> color.desaturated(50)
Color(0.75, 0.25, 0.25, alpha=1.0)
>>> color.desaturated(75)
Color(0.625, 0.375, 0.375, alpha=1.0)
>>> color.desaturated(100)
Color(0.5, 0.5, 0.5, alpha=1.0)
See Also
--------
:class:`compas.colors.ColorMap`
"""
DATASCHEMA = {
"type": "object",
"properties": {
"red": {"type": "number", "minimum": 0.0, "maximum": 1.0},
"green": {"type": "number", "minimum": 0.0, "maximum": 1.0},
"blue": {"type": "number", "minimum": 0.0, "maximum": 1.0},
"alpha": {"type": "number", "minimum": 0.0, "maximum": 1.0},
},
"required": ["red", "green", "blue", "alpha"],
}
@property
def __data__(self):
return {"red": self.r, "green": self.g, "blue": self.b, "alpha": self.a}
def __init__(self, red, green, blue, alpha=1.0, name=None):
super(Color, self).__init__(name=name)
self._r = 1.0
self._g = 1.0
self._b = 1.0
self._a = 1.0
self.r = red
self.g = green
self.b = blue
self.a = alpha
def __repr__(self):
return "{0}({1}, {2}, {3}, alpha={4})".format(type(self).__name__, self.r, self.g, self.b, self.a)
def __getitem__(self, key):
if key == 0:
return self.r
if key == 1:
return self.g
if key == 2:
return self.b
raise KeyError
def __len__(self):
return 3
def __iter__(self):
return iter(self.rgb)
def __eq__(self, other):
return all(a == b for a, b in zip(self, other))
# --------------------------------------------------------------------------
# Properties
# --------------------------------------------------------------------------
@property
def r(self):
return self._r
@r.setter
def r(self, red):
if red > 1.0 or red < 0.0:
raise ValueError("Components of an RGBA color should be in the range 0-1.")
self._r = red
@property
def g(self):
return self._g
@g.setter
def g(self, green):
if green > 1.0 or green < 0.0:
raise ValueError("Components of an RGBA color should be in the range 0-1.")
self._g = green
@property
def b(self):
return self._b
@b.setter
def b(self, blue):
if blue > 1.0 or blue < 0.0:
raise ValueError("Components of an RGBA color should be in the range 0-1.")
self._b = blue
@property
def a(self):
return self._a
@a.setter
def a(self, alpha):
if alpha > 1.0 or alpha < 0.0:
raise ValueError("Components of an RGBA color should be in the range 0-1.")
self._a = alpha
@property
def rgb(self):
r = self.r
g = self.g
b = self.b
return r, g, b
@property
def rgb255(self):
r = int(self.r * 255)
g = int(self.g * 255)
b = int(self.b * 255)
return r, g, b
@property
def rgba(self):
r, g, b = self.rgb
a = self.a
return r, g, b, a
@property
def rgba255(self):
r, g, b = self.rgb255
a = int(self.a * 255)
return r, g, b, a
@property
def hex(self):
return "#{0:02x}{1:02x}{2:02x}".format(*self.rgb255)
@property
def hls(self):
return colorsys.rgb_to_hls(*self.rgb)
@property
def hsv(self):
return colorsys.rgb_to_hsv(*self.rgb)
@property
def lightness(self):
return self.hls[1]
@property
def brightness(self):
return self.hsv[2]
@property
def is_light(self):
return self.luminance > 0.179
@property
def yuv(self):
y = self.luma
u, v = self.chroma
return y, u, v
@property
def luma(self):
return 0.299 * self.r + 0.587 * self.g + 0.114 * self.b
@property
def chroma(self):
y = self.luma
u = 0.492 * (self.b - y)
v = 0.877 * (self.r - y)
return u, v
@property
def luminance(self):
return 0.2126 * self.r + 0.7152 * self.g + 0.0722 * self.b
@property
def saturation(self):
maxval = max(self.r, self.g, self.b)
minval = min(self.r, self.g, self.b)
return (maxval - minval) / maxval
# --------------------------------------------------------------------------
# Constructors
# --------------------------------------------------------------------------
@classmethod
def from_rgb255(cls, r, g, b): # type: (int, int, int) -> Color
"""Construct a color from RGB255 components.
Parameters
----------
r : int & valuerange[0, 255]
Red component.
g : int & valuerange[0, 255]
Green component.
b : int & valuerange[0, 255]
Blue component.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(r / 255, g / 255, b / 255)
@classmethod
def from_hls(cls, hue, luminance, saturation): # type: (float, float, float) -> Color
"""Construct a color from Hue, Lightness, and Saturation.
Parameters
----------
hue : float
Hue.
lightness : float
Lightness.
saturation : float
Saturation.
Returns
-------
:class:`compas.colors.Color`
References
----------
https://en.wikipedia.org/wiki/HSL_and_HSV
"""
r, g, b = colorsys.hls_to_rgb(hue, luminance, saturation)
return cls(r, g, b)
@classmethod
def from_hsv(cls, h, s, v): # type: (float, float, float) -> Color
"""Construct a color from Hue, Saturation, and Value.
Parameters
----------
h : float
Hue.
s : float
Saturation.
v : float
Value.
Returns
-------
:class:`compas.colors.Color`
References
----------
https://en.wikipedia.org/wiki/HSL_and_HSV
"""
r, g, b = colorsys.hsv_to_rgb(h, s, v)
return cls(r, g, b)
@classmethod
def from_yiq(cls, y, i, q): # type: (float, float, float) -> Color
"""Construct a color from components in the YIQ color space.
Parameters
----------
y : float
Luma.
i : float
Orange-blue chroma.
q : float
Purple-green chroma.
Returns
-------
:class:`compas.colors.Color`
References
----------
https://en.wikipedia.org/wiki/YIQ
"""
r, g, b = colorsys.yiq_to_rgb(y, i, q)
return cls(r, g, b)
@classmethod
def from_yuv(cls, y, u, v): # type: (float, float, float) -> Color
"""Construct a color from components in the YUV color space.
Parameters
----------
y : float
Luma.
u : float
Blue projection chroma.
v : float
Red projection chroma.
Returns
-------
:class:`compas.colors.Color`
References
----------
https://en.wikipedia.org/wiki/YUV
"""
r = y + 1.140 * v
g = y - 0.395 * u - 0.581 * v
b = y + 2.032 * u
return cls(r, g, b)
@classmethod
def from_number(cls, number): # type: (float) -> Color
"""Construct a color from a single number in the range 0-1.
Parameters
----------
number : float
Number in the range 0-1, representing the color.
Returns
-------
:class:`compas.colors.Color`
"""
if number == 0.0:
r, g, b = 0, 0, 255
elif 0.0 < number < 0.25:
r, g, b = 0, int(255 * (4 * number)), 255
elif number == 0.25:
r, g, b = 0, 255, 255
elif 0.25 < number < 0.5:
r, g, b = 0, 255, int(255 - 255 * 4 * (number - 0.25))
elif number == 0.5:
r, g, b = 0, 255, 0
elif 0.5 < number < 0.75:
r, g, b = int(0 + 255 * 4 * (number - 0.5)), 255, 0
elif number == 0.75:
r, g, b = 255, 255, 0
elif 0.75 < number < 1.0:
(r, g, b) = (255, int(255 - 255 * 4 * (number - 0.75)), 0)
elif number == 1.0:
r, g, b = 255, 0, 0
else:
r, g, b = 0, 0, 0
return cls(r / 255.0, g / 255.0, b / 255.0)
from_i = from_number
@classmethod
def from_hex(cls, value): # type: (str) -> Color
"""Construct a color from a hexadecimal color value.
Parameters
----------
value : str
The hexadecimal color.
Returns
-------
:class:`compas.colors.Color`
"""
value = value.lstrip("#").lower()
r = HEX_DEC[value[0:2]]
g = HEX_DEC[value[2:4]]
b = HEX_DEC[value[4:6]]
return cls(r / 255.0, g / 255.0, b / 255.0)
@classmethod
def from_name(cls, name): # type: (str) -> Color
"""Construct a color from a name in the extended color table of HTML/CSS/SVG.
Parameters
----------
name : str
The color name. The name is case-insensitive.
Returns
-------
:class:`compas.colors.Color`
References
----------
https://www.w3.org/TR/css-color-3/#svg-color
"""
rgb255 = HTML_TO_RGB255.get(name.lower())
if rgb255 is None:
raise ValueError("Color name not found.")
return cls.from_rgb255(*rgb255)
@classmethod
def from_unknown(cls, unknown):
"""Construct a color from an unknown input.
Parameters
----------
unknown : str | tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`
The color input.
Returns
-------
:class:`compas.colors.Color` | None
Raises
------
:class:`ColorError`
"""
if not unknown:
return
if isinstance(unknown, cls):
return unknown
if Color._is_rgb255(unknown):
return cls.from_rgb255(*list(unknown))
if Color._is_hex(unknown):
return cls.from_hex(unknown)
if Color._is_rgb1(unknown):
return cls(*list(unknown))
if isinstance(unknown, basestring):
return cls.from_name(unknown)
raise ColorError
@staticmethod
def coerce(color):
"""Coerce a color input into a color.
Parameters
----------
color : str | tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`
The color input.
Returns
-------
:class:`compas.colors.Color` | None
Raises
------
ColorError
"""
if not color:
return
if Color._is_rgb255(color):
return Color.from_rgb255(*list(color))
if Color._is_hex(color):
return Color.from_hex(color)
if Color._is_rgb1(color):
return Color(*list(color))
raise ColorError
@staticmethod
def _is_rgb1(color):
"""Verify that the color is in the RGB 1 color space.
Returns
-------
bool
"""
return color and all(isinstance(c, float) and (c >= 0 and c <= 1) for c in color)
@staticmethod
def _is_rgb255(color):
"""Verify that the color is in the RGB 255 color space.
Returns
-------
bool
"""
return color and all(isinstance(c, int) and (c >= 0 and c <= 255) for c in color)
@staticmethod
def _is_hex(color):
"""Verify that the color is in hexadecimal format.
Returns
-------
bool
"""
if isinstance(color, basestring):
match = re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", color)
if match:
return True
return False
return False
# --------------------------------------------------------------------------
# Presets
# --------------------------------------------------------------------------
@classmethod
def white(cls):
"""Construct the color white.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 1.0, 1.0)
@classmethod
def black(cls):
"""Construct the color black.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 0.0, 0.0)
@classmethod
def grey(cls):
"""Construct the color grey.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.5, 0.5)
@classmethod
def red(cls):
"""Construct the color red.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 0.0, 0.0)
@classmethod
def orange(cls):
"""Construct the color orange.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 0.5, 0.0)
@classmethod
def yellow(cls):
"""Construct the color yellow.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 1.0, 0.0)
@classmethod
def lime(cls):
"""Construct the color lime (or chartreuse green).
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 1.0, 0.0)
@classmethod
def green(cls):
"""Construct the color green.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 1.0, 0.0)
@classmethod
def mint(cls):
"""Construct the color mint (or spring green).
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 1.0, 0.5)
@classmethod
def cyan(cls):
"""Construct the color cyan.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 1.0, 1.0)
@classmethod
def azure(cls):
"""Construct the color azure.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 0.5, 1.0)
@classmethod
def blue(cls):
"""Construct the color blue.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 0.0, 1.0)
@classmethod
def violet(cls):
"""Construct the color violet.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.0, 1.0)
@classmethod
def magenta(cls):
"""Construct the color magenta.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 0.0, 1.0)
@classmethod
def pink(cls):
"""Construct the color pink.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(1.0, 0.0, 0.5)
# --------------------------------------------------------------------------
# Other presets
# --------------------------------------------------------------------------
@classmethod
def maroon(cls):
"""Construct the color maroon.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.0, 0.0)
@classmethod
def brown(cls):
"""Construct the color brown.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.25, 0.0)
@classmethod
def olive(cls):
"""Construct the color olive.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.5, 0.0)
@classmethod
def teal(cls):
"""Construct the color teal.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 0.5, 0.5)
@classmethod
def navy(cls):
"""Construct the color navy.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.0, 0.0, 0.5)
@classmethod
def purple(cls):
"""Construct the color purple.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.5, 0.0, 0.5)
@classmethod
def silver(cls):
"""Construct the color silver.
Returns
-------
:class:`compas.colors.Color`
"""
return cls(0.75, 0.75, 0.75)
# ochre
# beige
# bordeaux
# hotpink
# steel
# midnight
# salmon
# --------------------------------------------------------------------------
# Methods
# --------------------------------------------------------------------------
def lighten(self, factor=10):
"""Lighten the color.
Parameters
----------
factor : float, optional
Percentage of lightness increase.
Returns
-------
None
Raises
------
ValueError
If the percentage of lightness increase is not in the range 0-100.
"""
if factor > 100 or factor < 0:
raise ValueError("Percentage of increased lightness should be in the range 0-100.")
factor = 1.0 + factor / 100
h, l, s = self.hls
r, g, b = colorsys.hls_to_rgb(h, min(1.0, l * factor), s)
self.r = r
self.g = g
self.b = b
def lightened(self, factor=10):
"""Return a lightened copy of the color.
Parameters
----------
factor : float, optional
Percentage of lightness increase.
Returns
-------
:class:`compas.colors.Color`
Raises
------
ValueError
If the percentage of lightness increase is not in the range 0-100.
"""
color = self.copy()
color.lighten(factor=factor)
return color
def darken(self, factor=10):
"""Darken the color.
Parameters
----------
factor : float, optional
Percentage of lightness reduction.
Returns
-------
None
Raises
------
ValueError
If the percentage of lightness reduction is not in the range 0-100.
"""
if factor > 100 or factor < 0:
raise ValueError("Percentage of reduced lightness should be in the range 0-100.")
factor = 1.0 - factor / 100
h, l, s = self.hls
r, g, b = colorsys.hls_to_rgb(h, max(0.0, l * factor), s)
self.r = r
self.g = g
self.b = b
def darkened(self, factor=10):
"""Return a darkened copy of the color.
Parameters
----------
factor : float, optional
Percentage of lightness reduction.
Returns
-------
:class:`compas.colors.Color`
Raises
------
ValueError
If the percentage of lightness reduction is not in the range 0-100.
"""
color = self.copy()
color.darken(factor=factor)
return color
def invert(self):
"""Invert the current color wrt to the RGB color circle.
Returns
-------
None
"""
self.r = 1.0 - self.r
self.g = 1.0 - self.g
self.b = 1.0 - self.b
def inverted(self):