summaryrefslogtreecommitdiff
path: root/embroider_simulate.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-01-01 15:26:18 -0500
committerLex Neva <github.com@lexneva.name>2018-01-01 15:26:18 -0500
commit09b9dd94e6591e0e74b8896c8cb8fdf173e32f5b (patch)
treec3f9afae8bc182c172dab6f880095cf94d21be46 /embroider_simulate.py
parent084dc783d2f2a94e77dfb6afe9b5a2ca14d7fc64 (diff)
adjust colors in the simulator to make them visible
Colors too close to white are darkened just a bit to make them stand out against the white background.
Diffstat (limited to 'embroider_simulate.py')
-rw-r--r--embroider_simulate.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/embroider_simulate.py b/embroider_simulate.py
index 31d3cd75..f3f9e5e2 100644
--- a/embroider_simulate.py
+++ b/embroider_simulate.py
@@ -4,6 +4,7 @@ import numpy
import wx
import inkex
import simplestyle
+import colorsys
from embroider import patches_to_stitches, stitches_to_polylines
@@ -102,6 +103,24 @@ class EmbroiderySimulator(wx.Frame):
return string
+ def color_to_pen(self, color):
+ # python colorsys module uses floats from 0 to 1.0
+ color = [value / 255.0 for value in color]
+
+ hls = list(colorsys.rgb_to_hls(*color))
+
+ # Our background is white. If the color is too close to white, then
+ # it won't be visible. Capping lightness should make colors visible
+ # without changing them too much.
+ hls[1] = min(hls[1], 0.85)
+
+ color = colorsys.hls_to_rgb(*hls)
+
+ # convert back to values in the range of 0-255
+ color = [value * 255 for value in color]
+
+ return wx.Pen(color)
+
def _patches_to_segments(self, patches):
stitches = patches_to_stitches(patches)
@@ -117,7 +136,7 @@ class EmbroiderySimulator(wx.Frame):
if stitch.color == last_color:
segments.append(((last_pos, pos), pen))
else:
- pen = wx.Pen(simplestyle.parseColor(stitch.color))
+ pen = self.color_to_pen(simplestyle.parseColor(stitch.color))
last_pos = pos
last_color = stitch.color
@@ -132,7 +151,7 @@ class EmbroiderySimulator(wx.Frame):
segments = []
pos = (0, 0)
- color = wx.Brush('black')
+ pen = wx.Brush('black')
cut = True
with open(stitch_file_path) as stitch_file:
@@ -144,7 +163,7 @@ class EmbroiderySimulator(wx.Frame):
if symbol == "$":
red, green, blue = fields[2:5]
- color = wx.Pen((int(red), int(green), int(blue)))
+ color = color_to_pen((int(red), int(green), int(blue)))
elif symbol == "*":
if command == "COLOR":
# change color
@@ -157,7 +176,7 @@ class EmbroiderySimulator(wx.Frame):
new_pos = (int(float(x) * 10), int(float(y) * 10))
if not cut:
- segments.append(((pos, new_pos), color))
+ segments.append(((pos, new_pos), pen))
cut = False
pos = new_pos