rsille/
lib.rs

1#![warn(missing_docs)]
2//! This crate is a rust lib for making [braille] art.
3//!
4//! You can use the basic canvas to paint something,
5//! or you can use Turtle to paint things like in python.
6//! And there are more useful things like colorful output, 3D object, life game and so on!
7//!
8//! ## Examples
9//!
10//! draw the sin(x)
11//! ```
12//! use rsille::Canvas;
13//! let mut c = Canvas::new();
14//! for x in 0..1800 {
15//!     let x = x as f64;
16//!     c.set(x / 10.0, 15.0 + x.to_radians().sin() * 10.0);
17//! }
18//! c.print();
19//! ```
20//!
21//! draw a star
22//! ```
23//! use rsille::{extra::Turtle, Canvas};
24//! let mut c = Canvas::new();
25//! let mut t = Turtle::new();
26//! for _ in 0..5 {
27//!     t.forward(30.0);
28//!     t.right(144.0);
29//! }
30//! c.paint(&t, 0.0, 15.0).unwrap();
31//! c.print();
32//! ```
33//!
34//! life game
35//! ```no_run
36//! use rsille::{extra::LifeGame, Animation};
37//! let lg =  LifeGame::from_path("path/to/rle").unwrap();
38//! let mut anime = Animation::new();
39//! anime.push(lg, |lg| lg.update(), (0.0, 0.0));
40//! anime.run();
41//! ```
42//!
43//! Want more examples? check the [examples](https://github.com/nidhoggfgg/rsille/tree/main/examples)
44//!
45//! ## Extra
46//!
47//! Useful things can paint on canvas:
48//! 1. [`Object3d`](extra/struct.Object3D.html) the 3d object
49//! 2. [`Turtle`](extra/struct.Turtle.html) similar to the turtle in python
50//! 3. [`Imagille`](extra/struct.Imgille.html) paint image to braille code
51//! 4. [`Lifegame`](extra/struct.LifeGame.html) the life game in braille code
52//!
53//! ## NOTE
54//!
55//! About (x, y), you can simply put on (0.0, 0.0) for one object, it will find the right position to paint.
56//! But if you want to build a animation or paint multiple objects,
57//! you may should find the right position by yourself.
58//!
59//! For example, this is a dot:
60//! ```text
61//! $ ./path/to/file # your terminal
62//! +--------+--------> x
63//! |         
64//! |
65//! +        ⣿
66//! |
67//! |
68//! v y
69//! ```
70//! This dot in terminal is (10, 4), because the left top corner is (1, 1).
71//! The y-axis is also facing down.
72//! It's different from the math coordinate system.
73//!
74//! But in the canvas, it's use the math coordinate system, and include the braille.
75//! Like a braille code "⣿", it has 2x4 dots, and it be thought as 8 dots not 1 dots.
76//! In the canvas, this dots B is `x` from 18.0 to 19.0, `y` from 8.0 to 11.0.
77//! And the dot A (the left top) is on (4.0, 11.0).
78//! ```text
79//! ^ y
80//! |         
81//! | A      B
82//! + ⠁      ⣿
83//! |
84//! |
85//! +--------+--------> x
86//! 0.0
87//! ```
88//!
89//! If you really don't know how to find the right position.
90//! Just try to paint your things at anyway and try to move it to another place and try again. :)
91//! And try to set x > 0 and y < 0, then the object will always in the screen and won't move.
92//!
93//! ## Other
94//!
95//! It's inspired by [drawille], but it has more features and fast
96//!
97//! [braille]: http://www.alanwood.net/unicode/braille_patterns.html
98//! [drawille]: https://github.com/asciimoo/drawille
99
100mod anime;
101mod braille;
102mod canvas;
103pub mod color;
104mod decor;
105mod defaults;
106pub mod extra;
107pub mod term;
108mod utils;
109
110pub use anime::Animation;
111pub use canvas::Canvas;
112pub use canvas::Paint;
113pub use decor::Decor;
114pub use utils::RsilleErr;