diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-06-25 23:46:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-25 23:46:50 +0200 |
| commit | 850958b5bc6017da66fad041dabc6ddd7b8d9f69 (patch) | |
| tree | 5ba42bcd4153631d58e9fb3d48ba25411f4adf74 /lib/threads/color.py | |
| parent | 75a9ea2e1dc16bfc8b41d9a747fdb29b5d3d0b14 (diff) | |
Simulator: make colors visible on background (#3010)
* simulator: color visible on background
* add design dimension info to simulator statusbar
* update preview when apply font size filter
* add info box
* preferences: check if stitch_plan is loaded
Diffstat (limited to 'lib/threads/color.py')
| -rw-r--r-- | lib/threads/color.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/threads/color.py b/lib/threads/color.py index 8b73c4f3..58861017 100644 --- a/lib/threads/color.py +++ b/lib/threads/color.py @@ -138,6 +138,34 @@ class ThreadColor(object): return ThreadColor(color, name=self.name, number=self.number, manufacturer=self.manufacturer, description=self.description, chart=self.chart) + def visible_on_background(self, background_color): + """A ThreadColor similar to this one but visible on given background color. + + Choose a color that's as close as possible to the actual thread color but is still at least + somewhat visible on given background. + """ + hls = list(colorsys.rgb_to_hls(*self.rgb_normalized)) + background = ThreadColor(background_color) + background_hls = list(colorsys.rgb_to_hls(*background.rgb_normalized)) + + difference = hls[1] - background_hls[1] + + if abs(difference) < 0.1: + if hls[1] > 0.5: + hls[1] -= 0.1 + else: + hls[1] += 0.1 + + color = colorsys.hls_to_rgb(*hls) + + # convert back to values in the range of 0-255 + color = tuple(value * 255 for value in color) + + return ThreadColor(color, name=self.name, number=self.number, manufacturer=self.manufacturer, + description=self.description, chart=self.chart) + + return self + @property def darker(self): hls = list(colorsys.rgb_to_hls(*self.rgb_normalized)) |
