Make text more readable on a background color
Posted: Sun Jul 07, 2019 9:07 pm
Ok, I'm working on another tutorial about Lc and colors, and although it is a very simple thing, I've managed to hit something I am not quite satisfied with, which is making the text on a background color readable.
The first code I attempted to do it with is just setting the text color to black or white based on an average of the RGB values divided by 2, which actually works out not too bad, but did have some inconsistencies...
Next, I tried using the inverse of the background color, but I'm not sure I really understand how to arrive at it correctly after reading a few articles about it. Again, there are some inconsistencies about how well it shows up...
And lastly, I tried a basic math solution on the values based on whether they were lighter or darker...
Which seems to work the best so far, until you get to certain members of the gray family of colors...
I also tried something Hermann posted, about setting the ink of the field to various things, but apparently that only works well if the background is a solid color and not a different color each line. Or at least I couldn't figure out how to get it to go in this setup.
What I'd be really interested in reading is someone that knows how to do something *like* setting the ink, which works out great in the script editor, but in a way where it takes the background color of each line into account.
Alternately, if someone knows how to simulate doing that, or just plain has a better way I haven't already thunk of
The first code I attempted to do it with is just setting the text color to black or white based on an average of the RGB values divided by 2, which actually works out not too bad, but did have some inconsistencies...
Code: Select all
put the backgroundColor of line x of field 1 into tmpCol
# determine a color offset to decide whether to use black or white text...
if sum(tmpCol) /2 < 160 then
set the textColor of line x of field 1 to "white"
else
set the textColor of line x of field 1 to "black"
end if
Code: Select all
put (255 - item 1 of tmpCol) & comma into tmpText1; put (255 - item 2 of tmpCol) & comma after tmpText1; put (255 - item 3 of tmpCol) after tmpText1;
set the textColor of line x of field 1 to tmpText1
Code: Select all
if item 1 of tmpCol > 180 then
put 55 into item 1 of tmpCol
else
put 180 into item 1 of tmpCol
end if
if item 2 of tmpCol > 180 then
put 55 into item 2 of tmpCol
else
put 180 into item 2 of tmpCol
end if
if item 3 of tmpCol > 180 then
put 55 into item 3 of tmpCol
else
put 180 into item 3 of tmpCol
end if
set the textColor of line x of field 1 to tmpCol
What I'd be really interested in reading is someone that knows how to do something *like* setting the ink, which works out great in the script editor, but in a way where it takes the background color of each line into account.
Alternately, if someone knows how to simulate doing that, or just plain has a better way I haven't already thunk of
