You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of two ways: separate red, gren, blue values (either as integers (0 to 255
49
+
range) or floats (0.0 to 1.0 range), either type is 'clamped' to valid range and
50
+
stored internally in the normalized (float) format), OR can accept a CHSV color as
51
+
input, which will be converted and stored in RGB format.
52
+
53
+
Following statements are equivalent - all return red:
54
+
55
+
.. code-block:: python
56
+
57
+
c = CRGB(255, 0, 0)
58
+
c = CRGB(1.0, 0.0, 0.0)
59
+
c = CRGB(CHSV(0.0, 1.0, 1.0))
47
60
"""
48
61
49
62
def__init__(self, red, green=0.0, blue=0.0):
50
-
""" Constructor for CRGB class.
51
-
ACCEPTS: One of two ways: separate red, gren, blue values (either
52
-
as integers (0 to 255 range) or floats (0.0 to 1.0 range),
53
-
either type is 'clamped' to valid range and stored
54
-
internally in the normalized (float) format),
55
-
OR can accept a CHSV color as input, which will be
56
-
converted and stored in RGB format.
57
-
Following statements are equivalent - all return red:
58
-
c = CRGB(255, 0, 0)
59
-
c = CRGB(1.0, 0.0, 0.0)
60
-
c = CRGB(CHSV(0.0, 1.0, 1.0))
61
-
RETURNS: CRGB instance.
62
-
"""
63
-
64
63
ifisinstance(red, CHSV):
65
64
# If first/only argument is a CHSV type, perform HSV to RGB
66
65
# conversion.
@@ -111,27 +110,24 @@ def __str__(self):
111
110
112
111
113
112
classCHSV(object):
114
-
""" HSV (hue, saturation, value) color class.
115
-
"""
113
+
"""Color stored in Hue, Saturation, Value color space.
116
114
117
-
def__init__(self, h, s=1.0, v=1.0):
118
-
""" Constructor for CHSV color class.
119
-
ACCEPTS: hue as float (any range) or integer (0-256 -> 0.0-1.0)
120
-
with no clamping performed (hue can 'wrap around'),
121
-
saturation and value as float (0.0 to 1.0) or integer
122
-
(0 to 255), both are clamped and stored internally in
123
-
the normalized (float) format. Latter two are optional,
124
-
can pass juse hue and saturation/value will default to 1.0.
125
-
Unlike CRGB (which can take a CHSV as input), there's
126
-
currently no equivalent RGB-to-HSV conversion, mostly
127
-
because it's a bit like trying to reverse a hash...
128
-
there may be multiple HSV solutions for a given RGB input.
129
-
This might be OK as long as conversion precedence is
130
-
documented, but otherwise (and maybe still) could cause
131
-
confusion as certain HSV->RGB->HSV translations won't
132
-
have the same input and output. Hmmm.
115
+
Accepts hue as float (any range) or integer (0-256 -> 0.0-1.0) with no clamping
116
+
performed (hue can 'wrap around'), saturation and value as float (0.0 to 1.0) or
117
+
integer (0 to 255), both are clamped and stored internally in the normalized (float)
118
+
format. Latter two are optional, can pass juse hue and saturation/value will
119
+
default to 1.0.
120
+
121
+
Unlike `CRGB` (which can take a `CHSV` as input), there's currently no equivalent
122
+
RGB-to-HSV conversion, mostly because it's a bit like trying to reverse a hash...
123
+
there may be multiple HSV solutions for a given RGB input.
124
+
125
+
This might be OK as long as conversion precedence is documented, but otherwise (and
126
+
maybe still) could cause confusion as certain HSV->RGB->HSV translations won't have
127
+
the same input and output. Hmmm.
133
128
"""
134
129
130
+
def__init__(self, h, s=1.0, v=1.0):
135
131
ifisinstance(h, float):
136
132
self.hue=h# Don't clamp! Hue can wrap around forever.
137
133
else:
@@ -153,18 +149,17 @@ def __str__(self):
153
149
154
150
155
151
defclamp(val, lower, upper):
156
-
"""Constrain value within a numeric range (inclusive).
152
+
"""Constrain value within a numeric range (inclusive).
157
153
"""
158
154
returnmax(lower, min(val, upper))
159
155
160
156
161
157
defnormalize(val, inplace=False):
162
-
""" Convert 8-bit (0 to 255) value to normalized (0.0 to 1.0) value.
163
-
ACCEPTS: integer, 0 to 255 range (input is clamped) or a list or tuple
164
-
of integers. In list case, 'inplace' can be used to control
165
-
whether the original list is modified (True) or a new list
166
-
is generated and returned (False).
167
-
RETURNS: float, 0.0 to 1.0 range, or list of floats (or None if inplace).
158
+
"""Convert 8-bit (0 to 255) value to normalized (0.0 to 1.0) value.
159
+
160
+
Accepts integer, 0 to 255 range (input is clamped) or a list or tuple of integers. In list case, 'inplace' can be used to control whether the original list is modified (True) or a new list is generated and returned (False).
161
+
162
+
Returns float, 0.0 to 1.0 range, or list of floats (or None if inplace).
0 commit comments