drawille-canvas HTML5 Canvas API for Terminal

0.1.3 · abandoned · verified Tue Apr 21

The `drawille-canvas` package provides an implementation of a subset of the HTML5 Canvas 2D API, specifically designed for rendering graphics within a terminal environment. It achieves this by utilizing Unicode braille characters through the underlying `drawille` library. Currently at version `0.1.3`, the project appears to be in an early, unmaintained, or abandoned state. The README explicitly notes improved performance on Node.js `v0.11` compared to `v0.10`, which are extremely old Node.js runtime versions, indicating the package was developed for historical environments. There is no clear release cadence, and active development for modern Node.js environments is highly improbable. Its primary value proposition was offering a familiar imperative Canvas-like drawing API for text-based interfaces.

Common errors

Warnings

Install

Imports

Quickstart

Illustrates how to initialize a Canvas, draw basic shapes like rectangles and lines, clear areas, apply transformations (translate, rotate), and output the braille-rendered frame to the console.

const Canvas = require('drawille-canvas');

const width = 80;
const height = 20;
const canvas = new Canvas(width, height);
const ctx = canvas; // CanvasRenderingContext2D methods are directly on the canvas object

// Draw a rectangle
ctx.fillRect(0, 0, 10, 5);

// Draw a line
ctx.beginPath();
ctx.moveTo(15, 2);
ctx.lineTo(25, 10);
ctx.stroke();

// Clear a portion
ctx.clearRect(2, 2, 3, 3);

// Translate and draw another rectangle
ctx.save();
ctx.translate(30, 5);
ctx.rotate(Math.PI / 4); // Rotate by 45 degrees
ctx.fillRect(0, 0, 8, 4);
ctx.restore();

// Draw something more complex to fill the space
for (let i = 0; i < 10; i++) {
  ctx.beginPath();
  ctx.moveTo(width - 1 - i * 3, 0);
  ctx.lineTo(width - 1 - i * 3, height - 1);
  ctx.stroke();
}

// Output the generated braille frame to the console
console.log(canvas.frame());

view raw JSON →