|
14 | 14 | import tqdm
|
15 | 15 |
|
16 | 16 |
|
17 |
| -def clamp(x, *, between): |
| 17 | +def clamp(x: float, /, *, between: tuple[int, int]) -> float: |
| 18 | + """ |
| 19 | + Restrict the value to fit between the lower/upper bounds. |
| 20 | + """ |
18 | 21 | lower, upper = between
|
19 | 22 | return min([max([x, lower]), upper])
|
20 | 23 |
|
@@ -55,8 +58,8 @@ def clamp(x, *, between):
|
55 | 58 |
|
56 | 59 | for (x_start, y_start), (r, g, b) in all_colours.items():
|
57 | 60 | hue, lightness, saturation = colorsys.rgb_to_hls(r / 255, g / 255, b / 255)
|
58 |
| - lightness = clamp(lightness * random.uniform(0.9, 1.1), between=[0, 1]) |
59 |
| - saturation = clamp(saturation * random.uniform(0.9, 1.1), between=[0, 1]) |
| 61 | + lightness = clamp(lightness * random.uniform(0.9, 1.1), between=(0, 1)) |
| 62 | + saturation = clamp(saturation * random.uniform(0.9, 1.1), between=(0, 1)) |
60 | 63 |
|
61 | 64 | r, g, b = colorsys.hls_to_rgb(hue, lightness, saturation)
|
62 | 65 | draw.rectangle(
|
|
0 commit comments