File size: 1,214 Bytes
b9c7f6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""AIFlow Math Ink 0.5의 JSON-like stroke μž…λ ₯ μ˜ˆμ‹œ."""

from pathlib import Path

from PIL import Image

from aiflow_math_ink_05 import (
    build_formula_grids,
    parse_writing_events,
    render_grid_images,
)


def main() -> None:
    """ν•„μš” λ³€μˆ˜: 예제 stroke payload. μž‘λ™ 원리: μˆ˜μ‹ 셀을 λ§Œλ“€κ³  UTF-8 경둜 μ•„λž˜ PNG둜 μ €μž₯ν•œλ‹€."""
    events = [
        {
            "stroke_id": 0,
            "width": 3,
            "points": [{"x": 24, "y": 20}, {"x": 36, "y": 20}],
        },
        {
            "stroke_id": 1,
            "width": 3,
            "points": [{"x": 10, "y": 42}, {"x": 60, "y": 42}],
        },
        {
            "stroke_id": 2,
            "width": 3,
            "points": [{"x": 24, "y": 64}, {"x": 36, "y": 64}],
        },
    ]
    strokes = parse_writing_events(events)
    grids = build_formula_grids(strokes)
    images = render_grid_images(Image.new("RGB", (80, 90), "white"), strokes, grids)
    output_directory = Path("outputs")
    output_directory.mkdir(exist_ok=True)
    for grid, image in zip(grids, images, strict=True):
        image.save(output_directory / f"cell-{grid.index}.png")


if __name__ == "__main__":
    main()