pub struct Canvas { /* private fields */ }Expand description
A canvas object that can be used to draw to the terminal using Braille characters.
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn new(width: u32, height: u32) -> Canvas
pub fn new(width: u32, height: u32) -> Canvas
Creates a new Canvas with the given width and height.
Note that the Canvas can still draw outside the given dimensions (expanding the canvas)
if a pixel is set outside the dimensions.
Examples found in repository?
More examples
6fn main() {
7 let mut canvas = Canvas::new(100, 100);
8 canvas.line_colored(2, 2, 80, 80, PixelColor::Red);
9 canvas.line_colored(2, 80, 80, 80, PixelColor::Green);
10 canvas.line_colored(2, 2, 2, 80, PixelColor::Blue);
11
12 canvas.line_colored(
13 2 + 5,
14 2 + 15,
15 80 + 5,
16 80 + 15,
17 PixelColor::TrueColor { r: 255, g: 0, b: 0 },
18 );
19 canvas.line_colored(
20 2 + 5,
21 80 + 15,
22 80 + 5,
23 80 + 15,
24 PixelColor::TrueColor { r: 0, g: 255, b: 0 },
25 );
26 canvas.line_colored(
27 2 + 5,
28 2 + 15,
29 2 + 5,
30 80 + 15,
31 PixelColor::TrueColor { r: 0, g: 0, b: 255 },
32 );
33 println!("{}", canvas.frame());
34}Sourcepub fn set_colored(&mut self, x: u32, y: u32, color: PixelColor)
pub fn set_colored(&mut self, x: u32, y: u32, color: PixelColor)
Sets a pixel at the specified coordinates. specifying the color of the braille char
Sourcepub fn set_char(&mut self, x: u32, y: u32, c: char)
pub fn set_char(&mut self, x: u32, y: u32, c: char)
Sets a letter at the specified coordinates.
Sourcepub fn text(&mut self, x: u32, y: u32, max_width: u32, text: &str)
pub fn text(&mut self, x: u32, y: u32, max_width: u32, text: &str)
Draws text at the specified coordinates (top-left of the text) up to max_width length
Sourcepub fn get(&self, x: u32, y: u32) -> bool
pub fn get(&self, x: u32, y: u32) -> bool
Detects whether the pixel at the given coordinates is set.
Sourcepub fn rows(&self) -> Vec<String>
pub fn rows(&self) -> Vec<String>
Returns a Vec of each row of the Canvas.
Note that each row is actually four pixels high due to the fact that a single Braille character spans two by four pixels.
Sourcepub fn frame(&self) -> String
pub fn frame(&self) -> String
Draws the canvas to a String and returns it.
Examples found in repository?
More examples
6fn main() {
7 let mut canvas = Canvas::new(100, 100);
8 canvas.line_colored(2, 2, 80, 80, PixelColor::Red);
9 canvas.line_colored(2, 80, 80, 80, PixelColor::Green);
10 canvas.line_colored(2, 2, 2, 80, PixelColor::Blue);
11
12 canvas.line_colored(
13 2 + 5,
14 2 + 15,
15 80 + 5,
16 80 + 15,
17 PixelColor::TrueColor { r: 255, g: 0, b: 0 },
18 );
19 canvas.line_colored(
20 2 + 5,
21 80 + 15,
22 80 + 5,
23 80 + 15,
24 PixelColor::TrueColor { r: 0, g: 255, b: 0 },
25 );
26 canvas.line_colored(
27 2 + 5,
28 2 + 15,
29 2 + 5,
30 80 + 15,
31 PixelColor::TrueColor { r: 0, g: 0, b: 255 },
32 );
33 println!("{}", canvas.frame());
34}Sourcepub fn line(&mut self, x1: u32, y1: u32, x2: u32, y2: u32)
pub fn line(&mut self, x1: u32, y1: u32, x2: u32, y2: u32)
Draws a line from (x1, y1) to (x2, y2) onto the Canvas.
Sourcepub fn line_colored(
&mut self,
x1: u32,
y1: u32,
x2: u32,
y2: u32,
color: PixelColor,
)
pub fn line_colored( &mut self, x1: u32, y1: u32, x2: u32, y2: u32, color: PixelColor, )
Draws a line from (x1, y1) to (x2, y2) onto the Canvas
specifying the color of the line
Examples found in repository?
6fn main() {
7 let mut canvas = Canvas::new(100, 100);
8 canvas.line_colored(2, 2, 80, 80, PixelColor::Red);
9 canvas.line_colored(2, 80, 80, 80, PixelColor::Green);
10 canvas.line_colored(2, 2, 2, 80, PixelColor::Blue);
11
12 canvas.line_colored(
13 2 + 5,
14 2 + 15,
15 80 + 5,
16 80 + 15,
17 PixelColor::TrueColor { r: 255, g: 0, b: 0 },
18 );
19 canvas.line_colored(
20 2 + 5,
21 80 + 15,
22 80 + 5,
23 80 + 15,
24 PixelColor::TrueColor { r: 0, g: 255, b: 0 },
25 );
26 canvas.line_colored(
27 2 + 5,
28 2 + 15,
29 2 + 5,
30 80 + 15,
31 PixelColor::TrueColor { r: 0, g: 0, b: 255 },
32 );
33 println!("{}", canvas.frame());
34}