@jworkshop/canvasasciifier

0.0.6 • Public • Published

canvasasciifier

A <pre> text React component which renders ascii from a canvas.

NPM version build status node version npm download

install

NPM

Usage

import React, { Component } from "react";
import ReactDOM from "react-dom";

import CanvasAsciifier from "@jworkshop/canvasasciifier";

import "./style.css";

class Example extends Component {
  someFunction() {
    const { myCanvas, myAsciifier } = this;

    /** Get the pre element with the generated ascii text. */
    myAsciifier.getTextElement();

    /** Update the pre element with generated ascii text. */
    asciifier.update(myCanvas);

    /** Generate ascii text from the canvas image data. */
    let asciiCode = myAsciifier.generateAsciiCode(myCanvas);
  }

  render() {

    return (
      <canvas
        ref={myCanvas => this.myCanvas = myCanvas}
      />
      <CanvasAsciifier
        ref={myAsciifier => this.myAsciifier = myAsciifier}
        className="className"
        style={ ... }
        textClassName="textClassName"
        textStyle={ ... }
        invert={true}
        asciiData={[" ", ".", ",", ";", "|", "*", "%", "@", "X", "#", "W", "M"]}
      />
    );
  }
}

ReactDOM.render(<Test />, document.getElementById("root"));

Readme

Keywords

Package Sidebar

Install

npm i @jworkshop/canvasasciifier

Weekly Downloads

6

Version

0.0.6

License

MIT

Unpacked Size

14.7 kB

Total Files

9

Last publish

Collaborators

  • jworkshop