Add smooth mosaic chars to box drawing

This commit is contained in:
Kovid Goyal 2020-09-02 22:00:58 +05:30
parent a935c80adc
commit a508161265
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 77 additions and 2 deletions

View File

@ -600,7 +600,7 @@ START_ALLOW_CASE_RANGE
case 0xe0ba: //  case 0xe0ba: // 
case 0xe0bc: //  case 0xe0bc: // 
case 0xe0be: //  case 0xe0be: // 
case 0x1fb00 ... 0x1fb3b: // sextants case 0x1fb00 ... 0x1fb67: // symbols for legacy computing
return BOX_FONT; return BOX_FONT;
default: default:
ans = in_symbol_maps(fg, cpu_cell->ch); ans = in_symbol_maps(fg, cpu_cell->ch);
@ -638,7 +638,7 @@ START_ALLOW_CASE_RANGE
return ch - 0x2500; // IDs from 0x00 to 0x9f return ch - 0x2500; // IDs from 0x00 to 0x9f
case 0xe0b0 ... 0xe0d4: case 0xe0b0 ... 0xe0d4:
return 0xa0 + ch - 0xe0b0; // IDs from 0xa0 to 0xc4 return 0xa0 + ch - 0xe0b0; // IDs from 0xa0 to 0xc4
case 0x1fb00 ... 0x1fb3b: case 0x1fb00 ... 0x1fb67:
return 0xc5 + ch - 0x1fb00; return 0xc5 + ch - 0x1fb00;
default: default:
return 0xffff; return 0xffff;

View File

@ -611,6 +611,29 @@ def sextant(buf: BufType, width: int, height: int, level: int = 1, which: int =
add_row(which // 16, 2) add_row(which // 16, 2)
@supersampled()
def smooth_mosaic(
buf: BufType, width: int, height: int, level: int = 1,
lower: bool = True, a: Tuple[float, float] = (0, 0), b: Tuple[float, float] = (0, 0)
) -> None:
ax, ay = int(a[0] * (width - 1)), int(a[1] * (height - 1))
bx, by = int(b[0] * (width - 1)), int(b[1] * (height - 1))
line = line_equation(ax, ay, bx, by)
def lower_condition(x: int, y: int) -> bool:
return y >= line(x)
def upper_condition(x: int, y: int) -> bool:
return y <= line(x)
condition = lower_condition if lower else upper_condition
for y in range(height):
offset = width * y
for x in range(width):
if condition(x, y):
buf[offset + x] = 255
box_chars: Dict[str, List[Callable]] = { box_chars: Dict[str, List[Callable]] = {
'': [hline], '': [hline],
'': [p(hline, level=3)], '': [p(hline, level=3)],
@ -710,6 +733,58 @@ box_chars: Dict[str, List[Callable]] = {
'': [p(quad, x=1)], '': [p(quad, x=1)],
'': [p(quad, x=1), p(quad, y=1)], '': [p(quad, x=1), p(quad, y=1)],
'': [p(quad, x=1), p(quad, y=1), p(quad, x=1, y=1)], '': [p(quad, x=1), p(quad, y=1), p(quad, x=1, y=1)],
'🬼': [p(smooth_mosaic, a=(0, 0.75), b=(0.5, 1))],
'🬽': [p(smooth_mosaic, a=(0, 0.75), b=(1, 1))],
'🬾': [p(smooth_mosaic, a=(0, 0.5), b=(0.5, 1))],
'🬿': [p(smooth_mosaic, a=(0, 0.5), b=(1, 1))],
'🭀': [p(smooth_mosaic, a=(0, 0), b=(0.5, 1))],
'🭁': [p(smooth_mosaic, a=(0, 0.25), b=(0.5, 0))],
'🭂': [p(smooth_mosaic, a=(0, 0.25), b=(1, 0))],
'🭃': [p(smooth_mosaic, a=(0, 0.75), b=(0.5, 0))],
'🭄': [p(smooth_mosaic, a=(0, 0.75), b=(1, 0))],
'🭅': [p(smooth_mosaic, a=(0, 1), b=(0.5, 0))],
'🭆': [p(smooth_mosaic, a=(0, 0.75), b=(1, 0.25))],
'🭇': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0.75))],
'🭈': [p(smooth_mosaic, a=(0, 1), b=(1, 0.75))],
'🭉': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0.25))],
'🭊': [p(smooth_mosaic, a=(0, 1), b=(1, 0.25))],
'🭋': [p(smooth_mosaic, a=(0.5, 1), b=(1, 0))],
'🭌': [p(smooth_mosaic, a=(0.5, 0), b=(1, 0.25))],
'🭍': [p(smooth_mosaic, a=(0, 0), b=(1, 0.25))],
'🭎': [p(smooth_mosaic, a=(0.5, 0), b=(1, 0.75))],
'🭏': [p(smooth_mosaic, a=(0, 0), b=(1, 0.75))],
'🭐': [p(smooth_mosaic, a=(0.5, 0), b=(1, 1))],
'🭑': [p(smooth_mosaic, a=(0, 0.25), b=(1, 0.75))],
'🭒': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(0.5, 1))],
'🭓': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 1))],
'🭔': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(0.5, 1))],
'🭕': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 1))],
'🭖': [p(smooth_mosaic, lower=False, a=(0, 0), b=(0.5, 1))],
'🭗': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(0.5, 0))],
'🭘': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 0))],
'🭙': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(0.5, 0))],
'🭚': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 0))],
'🭛': [p(smooth_mosaic, lower=False, a=(0, 1), b=(0.5, 0))],
'🭜': [p(smooth_mosaic, lower=False, a=(0, 0.75), b=(1, 0.25))],
'🭝': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0.75))],
'🭞': [p(smooth_mosaic, lower=False, a=(0, 1), b=(1, 0.75))],
'🭟': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0.25))],
'🭠': [p(smooth_mosaic, lower=False, a=(0, 1), b=(1, 0.25))],
'🭡': [p(smooth_mosaic, lower=False, a=(0.5, 1), b=(1, 0))],
'🭢': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 0.25))],
'🭣': [p(smooth_mosaic, lower=False, a=(0, 0), b=(1, 0.25))],
'🭤': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 0.75))],
'🭥': [p(smooth_mosaic, lower=False, a=(0, 0), b=(1, 0.75))],
'🭦': [p(smooth_mosaic, lower=False, a=(0.5, 0), b=(1, 1))],
'🭧': [p(smooth_mosaic, lower=False, a=(0, 0.25), b=(1, 0.75))],
} }
t, f = 1, 3 t, f = 1, 3