Skip to main content

Countdown to New Year's day 2026

Project description

Braille Canvas

A high-performance Braille canvas for terminal graphics in Python. Uses Unicode Braille characters (U+2800-U+28FF) to achieve 2x4 pixel resolution per character, allowing for detailed graphics in the terminal.

Features

  • High Resolution: Each Braille character represents a 2x4 pixel grid, providing excellent detail
  • 8-Color Palette: Supports standard ANSI terminal colors (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White)
  • Efficient Rendering: Optimized for performance with direct buffer manipulation
  • Line Drawing: Bresenham's algorithm for fast, accurate line drawing
  • Batch Plotting: Plot multiple points at once from any iterable

Installation

No external dependencies required! Uses only Python standard library.

Usage

Basic Example

from braille_canvas import BrailleCanvas

# Create a canvas (width and height in pixels)
canvas = BrailleCanvas(80, 40, default_color=0)

# Plot individual points
points = [(10, 10), (11, 10), (12, 11)]
canvas.plot(color=1, points=points)  # Red points

# Draw a line
canvas.line(x0=0, y0=0, x1=79, y1=39, color=2)  # Green diagonal

# Clear the canvas
canvas.clear(color=0)  # Clear with black

# Render to terminal
print(canvas.render())
# or simply
print(canvas)

Drawing Shapes

import math
from braille_canvas import BrailleCanvas

canvas = BrailleCanvas(80, 40, default_color=0)

# Draw a circle
center_x, center_y = 40, 20
radius = 15
circle_points = []
for angle in range(0, 360, 2):
    rad = math.radians(angle)
    x = int(center_x + radius * math.cos(rad))
    y = int(center_y + radius * math.sin(rad))
    circle_points.append((x, y))

canvas.plot(1, circle_points)  # Red circle
print(canvas)

API Reference

BrailleCanvas(width: int, height: int, default_color: int = 7)

Create a new Braille canvas.

  • width: Canvas width in pixels (not characters)
  • height: Canvas height in pixels (not characters)
  • default_color: Default color index (0-7), defaults to white

plot(color: int, points: Iterable[Tuple[int, int]])

Plot multiple points with the given color.

  • color: Color index (0-7)
  • points: Iterable of (x, y) coordinate tuples

line(x0: int, y0: int, x1: int, y1: int, color: int)

Draw a line using Bresenham's algorithm.

  • x0, y0: Starting point coordinates
  • x1, y1: Ending point coordinates
  • color: Color index (0-7)

clear(color: int = 7)

Clear the canvas with a single color.

  • color: Color index (0-7) to fill the canvas with

render() -> str

Render the canvas to a string with ANSI color codes.

Returns a string that can be printed to the terminal.

Color Palette

Index Color ANSI Code
0 Black \033[30m
1 Red \033[31m
2 Green \033[32m
3 Yellow \033[33m
4 Blue \033[34m
5 Magenta \033[35m
6 Cyan \033[36m
7 White \033[37m

How It Works

Braille Characters

Braille characters in Unicode use a 2x4 dot pattern:

0 3
1 4
2 5
6 7

Each dot can be individually controlled using bit positions in the Unicode range U+2800-U+28FF. This allows for 256 different patterns per character.

Performance

  • Direct Buffer Access: The canvas stores Braille patterns and colors in a 2D array for O(1) access
  • Efficient Line Drawing: Bresenham's algorithm draws lines without floating-point arithmetic
  • Color Optimization: Only emits ANSI color codes when the color changes

Running the Demo

python demo.py

The demo showcases:

  • Plotting points to create shapes
  • Drawing lines with the star pattern
  • Multi-colored sine waves
  • Grid patterns
  • Clear functionality

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ny2026-1.0.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ny2026-1.0.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file ny2026-1.0.0.tar.gz.

File metadata

  • Download URL: ny2026-1.0.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ny2026-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6816138df3cec72dd9ea9ec9532044e78dcd23bba9a6c90d05515b2aa8290d05
MD5 cc0c4552f70c55d2b5ee7f9a1082446e
BLAKE2b-256 037bb562a0d745204f6d6ddf883e325fa464aba53bab3c8d8136f874858241ae

See more details on using hashes here.

File details

Details for the file ny2026-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ny2026-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ny2026-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3c200db9518d53c21ada7ebe12e325b7e9cfca5b32b745846ce09cd35f70f09
MD5 ed1a8e0a953ee36107018bbfcd44e42c
BLAKE2b-256 e22a762a2188e3a88e5a6265a3c5f2b52c7e17e12c56cc7504f38de1b3575561

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page