kopia lustrzana https://github.com/inkstitch/inkstitch
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.pull/10/head
rodzic
084dc783d2
commit
09b9dd94e6
|
@ -4,6 +4,7 @@ import numpy
|
||||||
import wx
|
import wx
|
||||||
import inkex
|
import inkex
|
||||||
import simplestyle
|
import simplestyle
|
||||||
|
import colorsys
|
||||||
|
|
||||||
from embroider import patches_to_stitches, stitches_to_polylines
|
from embroider import patches_to_stitches, stitches_to_polylines
|
||||||
|
|
||||||
|
@ -102,6 +103,24 @@ class EmbroiderySimulator(wx.Frame):
|
||||||
|
|
||||||
return string
|
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):
|
def _patches_to_segments(self, patches):
|
||||||
stitches = patches_to_stitches(patches)
|
stitches = patches_to_stitches(patches)
|
||||||
|
|
||||||
|
@ -117,7 +136,7 @@ class EmbroiderySimulator(wx.Frame):
|
||||||
if stitch.color == last_color:
|
if stitch.color == last_color:
|
||||||
segments.append(((last_pos, pos), pen))
|
segments.append(((last_pos, pos), pen))
|
||||||
else:
|
else:
|
||||||
pen = wx.Pen(simplestyle.parseColor(stitch.color))
|
pen = self.color_to_pen(simplestyle.parseColor(stitch.color))
|
||||||
|
|
||||||
last_pos = pos
|
last_pos = pos
|
||||||
last_color = stitch.color
|
last_color = stitch.color
|
||||||
|
@ -132,7 +151,7 @@ class EmbroiderySimulator(wx.Frame):
|
||||||
segments = []
|
segments = []
|
||||||
|
|
||||||
pos = (0, 0)
|
pos = (0, 0)
|
||||||
color = wx.Brush('black')
|
pen = wx.Brush('black')
|
||||||
cut = True
|
cut = True
|
||||||
|
|
||||||
with open(stitch_file_path) as stitch_file:
|
with open(stitch_file_path) as stitch_file:
|
||||||
|
@ -144,7 +163,7 @@ class EmbroiderySimulator(wx.Frame):
|
||||||
|
|
||||||
if symbol == "$":
|
if symbol == "$":
|
||||||
red, green, blue = fields[2:5]
|
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 == "*":
|
elif symbol == "*":
|
||||||
if command == "COLOR":
|
if command == "COLOR":
|
||||||
# change color
|
# change color
|
||||||
|
@ -157,7 +176,7 @@ class EmbroiderySimulator(wx.Frame):
|
||||||
new_pos = (int(float(x) * 10), int(float(y) * 10))
|
new_pos = (int(float(x) * 10), int(float(y) * 10))
|
||||||
|
|
||||||
if not cut:
|
if not cut:
|
||||||
segments.append(((pos, new_pos), color))
|
segments.append(((pos, new_pos), pen))
|
||||||
|
|
||||||
cut = False
|
cut = False
|
||||||
pos = new_pos
|
pos = new_pos
|
||||||
|
|
Ładowanie…
Reference in New Issue