Improve shade character appearance

I was really unhappy with the previous checkerboard appearance, so I
changed it to supersampled diagonal lines. The fill ratios are still the
same, so it should still be compliant with the standard if I understood
it correctly.

Feel free to revert (or tell me to revert) this commit if you want the
previous look.
This commit is contained in:
MithicSpirit 2023-05-09 16:08:02 -04:00
parent a36fe45181
commit c883a024ba
No known key found for this signature in database
GPG Key ID: FEA8F724F2800E40

View File

@ -613,22 +613,20 @@ def inner_corner(buf: BufType, width: int, height: int, which: str = 'tl', level
draw_vline(buf, width, y1, y2, width // 2 + (xd * hgap), level) draw_vline(buf, width, y1, y2, width // 2 + (xd * hgap), level)
@supersampled()
def shade(buf: BufType, width: int, height: int, light: bool = False, invert: bool = False) -> None: def shade(buf: BufType, width: int, height: int, light: bool = False, invert: bool = False) -> None:
square_sz = max(1, width // 12) x_size = width / 4
number_of_rows = height // square_sz y_size = height / 8
number_of_cols = width // square_sz pattern_segments = 4 if light else 2
nums = range(square_sz) for y in range(height):
y_segment = y / y_size
for r in range(number_of_rows): offset = y * width
for c in range(number_of_cols): for x in range(width):
if invert ^ ((r % 2 != c % 2) or (light and r % 2 == 1)): segment = x/x_size + y_segment
continue section = int(segment) % pattern_segments
for yr in nums: enabled = section == 1
y = r * square_sz + yr if invert ^ enabled:
offset = width * y buf[offset + x] = 255
for xc in nums:
x = c * square_sz + xc
buf[offset + x] = 255
def quad(buf: BufType, width: int, height: int, x: int = 0, y: int = 0) -> None: def quad(buf: BufType, width: int, height: int, x: int = 0, y: int = 0) -> None: