File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -69,19 +69,15 @@ def linear_gradient(hexList: List[str], nColors: int) -> List[str]:
6969 input_color_bytes = [
7070 [int (_hex [i : i + 2 ], 16 ) for i in (1 , 3 , 5 )] for _hex in hexList
7171 ]
72- result : List [ str ] = []
73- step_size = ( len ( hexList ) - 1 ) / (nColors - 1 )
74- step = 0.0
75- idx = 0
76- while len ( result ) < nColors - 1 :
72+ result = []
73+ for output_idx in range (nColors - 1 ):
74+ output_fraction = ( len ( hexList ) - 1 ) * output_idx / ( nColors - 1 )
75+ idx = int ( output_fraction )
76+ fraction = output_fraction - idx
7777 start , end = input_color_bytes [idx ], input_color_bytes [idx + 1 ]
78- new_color_bytes = [int (x + step * (y - x )) for x , y in zip (start , end )]
78+ new_color_bytes = [int (x + fraction * (y - x )) for x , y in zip (start , end )]
7979 new_color_hexs = [hex (x )[2 :].zfill (2 ) for x in new_color_bytes ]
8080 result .append ("#" + "" .join (new_color_hexs ))
81- step += step_size
82- if step > 1 :
83- step -= 1
84- idx += 1
8581
8682 result .append (hexList [- 1 ].lower ())
8783 return result
You can’t perform that action at this time.
0 commit comments