Skip to main content

Crate rs3a

Crate rs3a 

Source
Expand description

An animated ASCII art rust library, implementing the 3a format.
Features:

§Used in

  • aaa – a TUI tool for rendering 3a files

§Examples of 3a art

§Other 3a implementations

§Example

You can run this example with cargo run --example edit-and-export

use rs3a::{Art, font::Font, CSSColorMap};
use std::fs::File;
use std::io::Write;

fn main() {
    // Reading
    let mut art = Art::from_file("./examples/dna.3a").unwrap();

    // Add new color mapping
    let color_pair = "fg:black bg:yellow".parse().unwrap();
    let color = art.search_or_create_color_map(color_pair);

    // Editing example: add frame numbers
    for frame in 0..art.frames() {
        art.print(frame, 0, 0, &format!("{}", frame), Some(Some(color)));
    }

    // Saving
    art.to_file("./examples/edited_dna.3a").unwrap();

    // Exporting to SVG
    let mut output = File::create("./examples/dna.svg").unwrap();
    write!(
        output, "{}",
        art.to_svg_frames(&CSSColorMap::default(), &Font::default())
    ).unwrap();

    // Exporting to asciicast (asciinema format).
    // You can play it with `asciinema play examples/dna.cast`.
    let mut output = File::create("./examples/dna.cast").unwrap();
    write!(output, "{}", art.to_asciicast2()).unwrap();

    // Printing as ANSI colored frames to stdout
    for frame in art.to_ansi_frames() {
        println!("{}\n", frame);
    }
}

§TODO

  • art optimisation
  • SVG render optimisation
  • conversion to
    • image
    • gif
    • video

§License

This project is licensed under either of

at your option.

Re-exports§

pub use art::Art;
pub use colors::CSSColorMap;
pub use colors::Color;
pub use colors::Color4;
pub use colors::ColorPair;
pub use colors::Palette;
pub use comments::Comments;
pub use content::Cell;
pub use content::Frame;
pub use content::Frames;
pub use delay::Delay;
pub use error::Error;
pub use error::Result;
pub use header::ExtraHeaderKey;
pub use header::Header;
pub use header::LegacyColorMode;
pub use header::LegacyHeaderInfo;
pub use header::Tagline;

Modules§

art
chars
colors
comments
content
delay
error
font
header