Skip to content

Commit e4e80ec

Browse files
added requested fixes, added more specificity to gamma_adjust.
1 parent aea2e2d commit e4e80ec

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

adafruit_fancyled/adafruit_fancyled.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
1414
* Author(s): PaintYourDragon
1515
"""
16-
from __future__ import annotations
17-
18-
# imports
1916

2017
__version__ = "0.0.0+auto.0"
2118
__repo__ = "https://github.com/Adafruit/Adafruit_CircuitPython_FancyLED.git"
2219

20+
# imports
2321
from math import floor
2422

2523
try:
24+
from __future__ import annotations
2625
from typing import Tuple, Union, Optional, List, Any
2726
from circuitpython_typing.led import FillBasedColorUnion
2827
except ImportError:
@@ -53,16 +52,16 @@ class CRGB:
5352
c = CRGB(CHSV(0.0, 1.0, 1.0))
5453
"""
5554

56-
def __init__(self, red: float, green: float = 0.0, blue: float = 0.0) -> None:
55+
def __init__(self, red: CHSV, green: float = 0.0, blue: float = 0.0) -> None:
5756
# pylint: disable=too-many-branches
5857
if isinstance(red, CHSV):
5958
# If first/only argument is a CHSV type, perform HSV to RGB
6059
# conversion.
61-
hsv = red # 'red' is CHSV, this is just more readable
62-
hue = hsv.hue * 6.0 # Hue circle = 0.0 to 6.0
63-
sxt = floor(hue) # Sextant index is next-lower integer of hue
64-
frac = hue - sxt # Fraction-within-sextant is 0.0 to <1.0
65-
sxt = int(sxt) % 6 # mod6 the sextant so it's always 0 to 5
60+
hsv: CHSV = red # 'red' is CHSV, this is just more readable
61+
hue: float = hsv.hue * 6.0 # Hue circle = 0.0 to 6.0
62+
sxt: int = floor(hue) # Sextant index is next-lower integer of hue
63+
frac: float = hue - sxt # Fraction-within-sextant is 0.0 to <1.0
64+
sxt: int = int(sxt) % 6 # mod6 the sextant so it's always 0 to 5
6665

6766
if sxt == 0: # Red to <yellow
6867
r, g, b = 1.0, frac, 0.0
@@ -77,7 +76,7 @@ def __init__(self, red: float, green: float = 0.0, blue: float = 0.0) -> None:
7776
else: # Magenta to <red
7877
r, g, b = 1.0, 0.0, 1.0 - frac
7978

80-
invsat = 1.0 - hsv.saturation # Inverse-of-saturation
79+
invsat: float = 1.0 - hsv.saturation # Inverse-of-saturation
8180

8281
self.red = ((r * hsv.saturation) + invsat) * hsv.value
8382
self.green = ((g * hsv.saturation) + invsat) * hsv.value
@@ -190,11 +189,11 @@ class CHSV:
190189
# pylint: disable=invalid-name
191190
def __init__(self, h: float, s: float = 1.0, v: float = 1.0) -> None:
192191
if isinstance(h, float):
193-
self.hue = h # Don't clamp! Hue can wrap around forever.
192+
self.hue: float = h # Don't clamp! Hue can wrap around forever.
194193
else:
195-
self.hue = float(h) / 256.0
196-
self.saturation = clamp_norm(s)
197-
self.value = clamp_norm(v)
194+
self.hue: float = float(h) / 256.0
195+
self.saturation: float = clamp_norm(s)
196+
self.value: float = clamp_norm(v)
198197

199198
def __repr__( # pylint: disable=invalid-repr-returned
200199
self,
@@ -284,7 +283,7 @@ def clamp_norm(val: Union[float, int]) -> Union[float, int]:
284283

285284

286285
def denormalize(
287-
val: Union[float, List[float], Tuple[float]], inplace=False
286+
val: Union[float, List[float], Tuple[float]], inplace: bool = False
288287
) -> Union[int, List[int]]:
289288
"""Convert normalized (0.0 to 1.0) value to 8-bit (0 to 255) value
290289
@@ -387,7 +386,10 @@ def mix(
387386

388387

389388
def gamma_adjust(
390-
val: Any, gamma_value: Any = None, brightness: Any = 1.0, inplace=False
389+
val: Any,
390+
gamma_value: Any = None,
391+
brightness: Optional[Union[float, Tuple[int, int, int]]] = 1.0,
392+
inplace: Optional[bool] = False,
391393
) -> Union[float, CRGB, List[Union[float, CRGB]]]:
392394
"""Provides gamma adjustment for single values, `CRGB` and `CHSV` types
393395
and lists of any of these.

0 commit comments

Comments
 (0)