Skip to content

About

Like paint by numbers, but paint by char(acter)s! Python package, which takes a 2D grid of chars and turns that into an image with each square colored by the char's value in that square.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

PaintByChar

PaintByChar logo

License: MIT Python 3.12 PyPI version Docs Tests

A tiny Python library for turning ASCII grids into colorful images. It is designed for quick visualizations of mazes, maps, game boards, and Advent of Code-style 2D text puzzles.

Why PaintByChar?

  • Turn a rectangular text grid into a rendered image in a few lines
  • Map each character to a color automatically or via your own palette
  • Support multiple rendering styles for cells, text, and background-label combinations
  • Works well for generative art, puzzle visualizations, and debugging text-based layouts

Features

  • string_to_image() for direct text-to-image conversion
  • file_to_image() for processing a text file as a grid
  • Preset colormaps such as viridis, plasma, and terrain
  • Custom value_colors dictionaries for full control over mapping
  • Render modes: filled cells, colored text, and colored cells with background text
  • Comes bundled with RobotoMono-Regular.ttf
    • Provide a path to any true type font to use that instead!

Install

pip install paintbychar

Quick example

import paintbychar as pbc

grid = """0123
4567
89AB
"""

img = pbc.string_to_image(
    grid,
    preset="viridis",
    cell_size=24,
    render_style=pbc.RenderStyle.COLORED_CELLS,
)

pbc.save_image(img, "output_basic.png")

Example output

Basic example output

More example images

Styled text output Preset output

More examples

The repository includes several runnable examples in the examples/ folder, including:

  • basic_example.py
  • file_example.py
  • styles_example.py
  • preset_example.py
  • advent_of_code_example.py

API reference

See the documentation for a quick overview of the public functions and options, or browse the live docs site.

There is also documentation on Read the Docs with installation instructions, usage examples, and API reference. Read the Docs

Contributing

Contributions are welcome. See CONTRIBUTING.md for setup instructions, testing guidance, and the pull request process.

Code of conduct

This project follows the Contributor Covenant Code of Conduct.

License

This project is licensed under the MIT License.

The bundled Roboto Mono font is separately licensed under the SIL Open Font License (OFL). See src/fonts/OFL.txt for its license terms.

Project status

PaintByChar is currently a small, focused library aimed at grid-based text rendering and visualization. It is suitable for personal, educational, and open-source use, and is prepared for broader community contributions as it matures.

Social preview

A repository preview image is included in assets/social-preview.png and can be used as a GitHub social preview or banner asset.

About

Like paint by numbers, but paint by char(acter)s! Python package, which takes a 2D grid of chars and turns that into an image with each square colored by the char's value in that square.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages