mirror of
https://github.com/1j01/textual-paint.git
synced 2024-09-11 15:56:03 +03:00
Add a threshold to Color Eraser, comparing color components
This commit is contained in:
parent
7bbca533b2
commit
b46273cf9f
12
paint.py
12
paint.py
@ -1297,7 +1297,7 @@ class PaintApp(App[None]):
|
||||
char = self.image.ch[y][x]
|
||||
# fg_color = self.selected_bg_color if self.image.fg[y][x] == self.selected_fg_color else self.image.fg[y][x]
|
||||
# bg_color = self.selected_bg_color if self.image.bg[y][x] == self.selected_fg_color else self.image.bg[y][x]
|
||||
|
||||
|
||||
# Use color comparison instead of string comparison because "#000000" != "rgb(0,0,0)"
|
||||
# This stuff might be simpler and more efficient if we used Color objects in the document model
|
||||
style = Style.parse(self.image.fg[y][x]+" on "+self.image.bg[y][x])
|
||||
@ -1305,8 +1305,14 @@ class PaintApp(App[None]):
|
||||
assert style.color is not None
|
||||
assert style.bgcolor is not None
|
||||
assert selected_fg_style.color is not None
|
||||
fg_matches = style.color.triplet == selected_fg_style.color.triplet
|
||||
bg_matches = style.bgcolor.triplet == selected_fg_style.color.triplet
|
||||
# fg_matches = style.color.triplet == selected_fg_style.color.triplet
|
||||
# bg_matches = style.bgcolor.triplet == selected_fg_style.color.triplet
|
||||
threshold = 5
|
||||
assert style.color.triplet is not None
|
||||
assert style.bgcolor.triplet is not None
|
||||
assert selected_fg_style.color.triplet is not None
|
||||
fg_matches = abs(style.color.triplet[0] - selected_fg_style.color.triplet[0]) < threshold and abs(style.color.triplet[1] - selected_fg_style.color.triplet[1]) < threshold and abs(style.color.triplet[2] - selected_fg_style.color.triplet[2]) < threshold
|
||||
bg_matches = abs(style.bgcolor.triplet[0] - selected_fg_style.color.triplet[0]) < threshold and abs(style.bgcolor.triplet[1] - selected_fg_style.color.triplet[1]) < threshold and abs(style.bgcolor.triplet[2] - selected_fg_style.color.triplet[2]) < threshold
|
||||
fg_color = self.selected_bg_color if fg_matches else self.image.fg[y][x]
|
||||
bg_color = self.selected_bg_color if bg_matches else self.image.bg[y][x]
|
||||
if self.selected_tool == Tool.airbrush:
|
||||
|
Loading…
Reference in New Issue
Block a user