Expand description
This crate is a rust lib for making braille art.
You can use the basic canvas to paint something, or you can use Turtle to paint things like in python. And there are more useful things like colorful output, 3D object, life game and so on!
§Examples
draw the sin(x)
use rsille::Canvas;
let mut c = Canvas::new();
for x in 0..1800 {
let x = x as f64;
c.set(x / 10.0, 15.0 + x.to_radians().sin() * 10.0);
}
c.print();
draw a star
use rsille::{extra::Turtle, Canvas};
let mut c = Canvas::new();
let mut t = Turtle::new();
for _ in 0..5 {
t.forward(30.0);
t.right(144.0);
}
c.paint(&t, 0.0, 15.0).unwrap();
c.print();
life game
use rsille::{extra::LifeGame, Animation};
let lg = LifeGame::from_path("path/to/rle").unwrap();
let mut anime = Animation::new();
anime.push(lg, |lg| lg.update(), (0.0, 0.0));
anime.run();
Want more examples? check the examples
§Extra
Useful things can paint on canvas:
Object3d
the 3d objectTurtle
similar to the turtle in pythonImagille
paint image to braille codeLifegame
the life game in braille code
§NOTE
About (x, y), you can simply put on (0.0, 0.0) for one object, it will find the right position to paint. But if you want to build a animation or paint multiple objects, you may should find the right position by yourself.
For example, this is a dot:
$ ./path/to/file # your terminal
+--------+--------> x
|
|
+ ⣿
|
|
v y
This dot in terminal is (10, 4), because the left top corner is (1, 1). The y-axis is also facing down. It’s different from the math coordinate system.
But in the canvas, it’s use the math coordinate system, and include the braille.
Like a braille code “⣿”, it has 2x4 dots, and it be thought as 8 dots not 1 dots.
In the canvas, this dots B is x
from 18.0 to 19.0, y
from 8.0 to 11.0.
And the dot A (the left top) is on (4.0, 11.0).
^ y
|
| A B
+ ⠁ ⣿
|
|
+--------+--------> x
0.0
If you really don’t know how to find the right position. Just try to paint your things at anyway and try to move it to another place and try again. :) And try to set x > 0 and y < 0, then the object will always in the screen and won’t move.
§Other
It’s inspired by drawille, but it has more features and fast
Modules§
- Colors in Terminal
- Some useful things can paint on the canvas
- Some useful function to print styles in terminal
Macros§
- A help macro for plot functions easy
Structs§
- Create an animation
- The basic canvas
- The box outside the object
- The error type used by this crate
Traits§
- Implement this for painting on
Canvas