13
13
14
14
* Author(s): PaintYourDragon
15
15
"""
16
- from __future__ import annotations
17
-
18
- # imports
19
16
20
17
__version__ = "0.0.0+auto.0"
21
18
__repo__ = "https://github.com/Adafruit/Adafruit_CircuitPython_FancyLED.git"
22
19
20
+ # imports
23
21
from math import floor
24
22
25
23
try :
24
+ from __future__ import annotations
26
25
from typing import Tuple , Union , Optional , List , Any
27
26
from circuitpython_typing .led import FillBasedColorUnion
28
27
except ImportError :
@@ -53,16 +52,16 @@ class CRGB:
53
52
c = CRGB(CHSV(0.0, 1.0, 1.0))
54
53
"""
55
54
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 :
57
56
# pylint: disable=too-many-branches
58
57
if isinstance (red , CHSV ):
59
58
# If first/only argument is a CHSV type, perform HSV to RGB
60
59
# 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
66
65
67
66
if sxt == 0 : # Red to <yellow
68
67
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:
77
76
else : # Magenta to <red
78
77
r , g , b = 1.0 , 0.0 , 1.0 - frac
79
78
80
- invsat = 1.0 - hsv .saturation # Inverse-of-saturation
79
+ invsat : float = 1.0 - hsv .saturation # Inverse-of-saturation
81
80
82
81
self .red = ((r * hsv .saturation ) + invsat ) * hsv .value
83
82
self .green = ((g * hsv .saturation ) + invsat ) * hsv .value
@@ -190,11 +189,11 @@ class CHSV:
190
189
# pylint: disable=invalid-name
191
190
def __init__ (self , h : float , s : float = 1.0 , v : float = 1.0 ) -> None :
192
191
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.
194
193
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 )
198
197
199
198
def __repr__ ( # pylint: disable=invalid-repr-returned
200
199
self ,
@@ -284,7 +283,7 @@ def clamp_norm(val: Union[float, int]) -> Union[float, int]:
284
283
285
284
286
285
def denormalize (
287
- val : Union [float , List [float ], Tuple [float ]], inplace = False
286
+ val : Union [float , List [float ], Tuple [float ]], inplace : bool = False
288
287
) -> Union [int , List [int ]]:
289
288
"""Convert normalized (0.0 to 1.0) value to 8-bit (0 to 255) value
290
289
@@ -387,7 +386,10 @@ def mix(
387
386
388
387
389
388
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 ,
391
393
) -> Union [float , CRGB , List [Union [float , CRGB ]]]:
392
394
"""Provides gamma adjustment for single values, `CRGB` and `CHSV` types
393
395
and lists of any of these.
0 commit comments