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-0.1.0a1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file ny2026-0.1.0a1.tar.gz.

File metadata

  • Download URL: ny2026-0.1.0a1.tar.gz
  • Upload date:
  • Size: 11.7 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-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 677b784565c87e479446821e7d585ee355408ea27903ed2ca85ce488bbcbf94c
MD5 b0dd5987ee9a99d3f29ffe3399b2147a
BLAKE2b-256 bd8f6eb063c55d5fad405378626085684e08fa15f555726a4a0592993c1b2f6e

See more details on using hashes here.

File details

Details for the file ny2026-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: ny2026-0.1.0a1-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-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4eeea43a12584ddbca3e6f7de90c25c31be1d94b0eb6e67453a19b7fe8665d
MD5 a727c03592423d534c032e511c140840
BLAKE2b-256 e32612b69f9f1a5dae190d9c571beb44336d61d9c00774c9b578996ed0e1a00a

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