From 850958b5bc6017da66fad041dabc6ddd7b8d9f69 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:46:50 +0200 Subject: 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 --- lib/threads/color.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/threads/color.py') 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)) -- cgit v1.2.3