Screen

Struct Screen 

Source
pub struct Screen { /* private fields */ }
Expand description

the screen struct, used to attach canvases

Implementations§

Source§

impl Screen

Source

pub fn new(width: u8, height: u8, color: PixelColors) -> Option<Screen>

defines a new screen #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors};
 let screen1 = Screen::new(25,25,PixelColors::Red).unwrap();

creates a new 25x25 blank red screen

Examples found in repository?
examples/shapes/main.rs (line 25)
6fn main(){
7    let mut vecan = Vec::new();
8    let mut shape1 = Vec::new();
9    //one way to make a smily face
10    shape1.push(vec![2,2,0,2,2]);
11    shape1.push(vec![2,2,0,2,2]);
12    shape1.push(vec![0,0,0,0,0]);
13    shape1.push(vec![0,0,1,0,0]);
14    shape1.push(vec![8,0,0,0,8]);
15    shape1.push(vec![8,8,8,8,8]);
16    //another
17    let shape2 =square(2,PixelColors::Blue).unwrap() ;
18    let shape3 =line(5,PixelColors::White,false).unwrap();
19    let shape4 =square(1,PixelColors::Red).unwrap();
20    let shape5 =rectangle(9,10,PixelColors::Magenta).unwrap();
21    let shape6 =triangle(9,PixelColors::Magenta).unwrap();
22    let mut vecer = Vec::new();
23    vecer.push(vec![8,0,0,0,8]);
24    let mut canvas1 = Canvas::new(30,30,PixelColors::Black).unwrap(); 
25    let mut screen1 = Screen::new(35,35,PixelColors::Black).unwrap();
26    screen1.attach_pixels(&shape1,1,1).unwrap();
27    let mut screen2 = Screen::new(35,35,PixelColors::Black).unwrap();
28    canvas1.attach(&shape5,8,8).unwrap();
29    canvas1.attach(&shape2,10,10).unwrap();
30    canvas1.attach(&shape2,13,10).unwrap();
31    canvas1.attach(&shape4,12,13).unwrap();
32    canvas1.attach(&vecer,10,14).unwrap();
33    canvas1.attach(&shape3,10,15).unwrap();
34    canvas1.attach(&shape6,16,16).unwrap();
35    screen2.attach(&canvas1,0,0);
36
37    &vecan.push(screen1);
38    &vecan.push(screen2);
39    let mut animation = Animation::new(vecan,15,10);
40    animation.play();
41}
More examples
Hide additional examples
examples/simple/main.rs (line 29)
4fn main(){
5    let mut vecan = Vec::new();
6    let mut shape1 = Vec::new();
7    shape1.push(vec![1,1,0,1,1]);
8    shape1.push(vec![1,1,0,1,1]);
9    shape1.push(vec![0,0,0,0,0]);
10    shape1.push(vec![0,0,1,0,0]);
11    shape1.push(vec![1,0,0,0,1]);
12    shape1.push(vec![1,1,1,1,1]);
13    let mut shape2 = Vec::new();
14    shape2.push(vec![1,1,1,1,1]);
15    shape2.push(vec![1,0,0,0,1]);
16    shape2.push(vec![1,0,0,0,1]);
17    shape2.push(vec![1,0,0,0,1]);
18    shape2.push(vec![1,0,0,0,1]);
19    shape2.push(vec![1,1,1,1,1]);
20    let mut shape3 = Vec::new();
21    shape3.push(vec![0,0,0,0,0]);
22    shape3.push(vec![0,0,1,0,0]);
23    shape3.push(vec![0,1,1,1,0]);
24    shape3.push(vec![0,1,1,1,0]);
25    shape3.push(vec![0,0,1,0,0]);
26    shape3.push(vec![0,0,0,0,0]);
27    // this is a rather basic and none usable example, if you would really like to learn how to use
28    // the library you should go to oter examples
29    let mut screen1 = Screen::new(25,25,PixelColors::Green).unwrap();
30    let mut canvas1 = Canvas::new(17,17,PixelColors::Green).unwrap();
31    canvas1.attach(&shape1,1,1).unwrap();
32    canvas1.attach(&shape2,10,10).unwrap();
33    screen1.attach(&canvas1,0,0).unwrap();
34    let mut screen2 = Screen::new(25,25,PixelColors::Green).unwrap();
35    let mut canvas2 = Canvas::new(17,17,PixelColors::Green).unwrap();
36    canvas2.attach(&shape1,1,1).unwrap();
37    canvas2.attach(&shape3,10,10).unwrap();
38    screen2.attach(&canvas2,0,0).unwrap();
39    &vecan.push(screen1);
40    &vecan.push(screen2);
41    let mut animation = Animation::new(vecan,15,10);
42    animation.play();
43
44
45}
Source

pub fn print_screen(&self)

output function, should not usually be used, you should use animation.play()

Source

pub fn attach_pixels( &mut self, shape: &Vec<Vec<u8>>, x: u8, y: u8, ) -> Result<(), &str>

needed in case anyone is realy into vecs….

Examples found in repository?
examples/shapes/main.rs (line 26)
6fn main(){
7    let mut vecan = Vec::new();
8    let mut shape1 = Vec::new();
9    //one way to make a smily face
10    shape1.push(vec![2,2,0,2,2]);
11    shape1.push(vec![2,2,0,2,2]);
12    shape1.push(vec![0,0,0,0,0]);
13    shape1.push(vec![0,0,1,0,0]);
14    shape1.push(vec![8,0,0,0,8]);
15    shape1.push(vec![8,8,8,8,8]);
16    //another
17    let shape2 =square(2,PixelColors::Blue).unwrap() ;
18    let shape3 =line(5,PixelColors::White,false).unwrap();
19    let shape4 =square(1,PixelColors::Red).unwrap();
20    let shape5 =rectangle(9,10,PixelColors::Magenta).unwrap();
21    let shape6 =triangle(9,PixelColors::Magenta).unwrap();
22    let mut vecer = Vec::new();
23    vecer.push(vec![8,0,0,0,8]);
24    let mut canvas1 = Canvas::new(30,30,PixelColors::Black).unwrap(); 
25    let mut screen1 = Screen::new(35,35,PixelColors::Black).unwrap();
26    screen1.attach_pixels(&shape1,1,1).unwrap();
27    let mut screen2 = Screen::new(35,35,PixelColors::Black).unwrap();
28    canvas1.attach(&shape5,8,8).unwrap();
29    canvas1.attach(&shape2,10,10).unwrap();
30    canvas1.attach(&shape2,13,10).unwrap();
31    canvas1.attach(&shape4,12,13).unwrap();
32    canvas1.attach(&vecer,10,14).unwrap();
33    canvas1.attach(&shape3,10,15).unwrap();
34    canvas1.attach(&shape6,16,16).unwrap();
35    screen2.attach(&canvas1,0,0);
36
37    &vecan.push(screen1);
38    &vecan.push(screen2);
39    let mut animation = Animation::new(vecan,15,10);
40    animation.play();
41}
Source

pub fn attach(&mut self, canvas: &Canvas, x: u8, y: u8) -> Result<(), &str>

attach takes a drawn upon canvas and attaches it to the screen at a given point #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors,Canvas};
 use termi_graphics::shapes::line;
 let mut screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let mut canvas1 = Canvas::new(5,5,PixelColors::Red).unwrap();
 let ln1 = line(4,PixelColors::Green,false).unwrap();
 canvas1.attach(&ln1,1,1).unwrap();
 screen1.attach(&canvas1,10,10).unwrap();

creates a new 25x25 blank red screen

Examples found in repository?
examples/shapes/main.rs (line 35)
6fn main(){
7    let mut vecan = Vec::new();
8    let mut shape1 = Vec::new();
9    //one way to make a smily face
10    shape1.push(vec![2,2,0,2,2]);
11    shape1.push(vec![2,2,0,2,2]);
12    shape1.push(vec![0,0,0,0,0]);
13    shape1.push(vec![0,0,1,0,0]);
14    shape1.push(vec![8,0,0,0,8]);
15    shape1.push(vec![8,8,8,8,8]);
16    //another
17    let shape2 =square(2,PixelColors::Blue).unwrap() ;
18    let shape3 =line(5,PixelColors::White,false).unwrap();
19    let shape4 =square(1,PixelColors::Red).unwrap();
20    let shape5 =rectangle(9,10,PixelColors::Magenta).unwrap();
21    let shape6 =triangle(9,PixelColors::Magenta).unwrap();
22    let mut vecer = Vec::new();
23    vecer.push(vec![8,0,0,0,8]);
24    let mut canvas1 = Canvas::new(30,30,PixelColors::Black).unwrap(); 
25    let mut screen1 = Screen::new(35,35,PixelColors::Black).unwrap();
26    screen1.attach_pixels(&shape1,1,1).unwrap();
27    let mut screen2 = Screen::new(35,35,PixelColors::Black).unwrap();
28    canvas1.attach(&shape5,8,8).unwrap();
29    canvas1.attach(&shape2,10,10).unwrap();
30    canvas1.attach(&shape2,13,10).unwrap();
31    canvas1.attach(&shape4,12,13).unwrap();
32    canvas1.attach(&vecer,10,14).unwrap();
33    canvas1.attach(&shape3,10,15).unwrap();
34    canvas1.attach(&shape6,16,16).unwrap();
35    screen2.attach(&canvas1,0,0);
36
37    &vecan.push(screen1);
38    &vecan.push(screen2);
39    let mut animation = Animation::new(vecan,15,10);
40    animation.play();
41}
More examples
Hide additional examples
examples/simple/main.rs (line 33)
4fn main(){
5    let mut vecan = Vec::new();
6    let mut shape1 = Vec::new();
7    shape1.push(vec![1,1,0,1,1]);
8    shape1.push(vec![1,1,0,1,1]);
9    shape1.push(vec![0,0,0,0,0]);
10    shape1.push(vec![0,0,1,0,0]);
11    shape1.push(vec![1,0,0,0,1]);
12    shape1.push(vec![1,1,1,1,1]);
13    let mut shape2 = Vec::new();
14    shape2.push(vec![1,1,1,1,1]);
15    shape2.push(vec![1,0,0,0,1]);
16    shape2.push(vec![1,0,0,0,1]);
17    shape2.push(vec![1,0,0,0,1]);
18    shape2.push(vec![1,0,0,0,1]);
19    shape2.push(vec![1,1,1,1,1]);
20    let mut shape3 = Vec::new();
21    shape3.push(vec![0,0,0,0,0]);
22    shape3.push(vec![0,0,1,0,0]);
23    shape3.push(vec![0,1,1,1,0]);
24    shape3.push(vec![0,1,1,1,0]);
25    shape3.push(vec![0,0,1,0,0]);
26    shape3.push(vec![0,0,0,0,0]);
27    // this is a rather basic and none usable example, if you would really like to learn how to use
28    // the library you should go to oter examples
29    let mut screen1 = Screen::new(25,25,PixelColors::Green).unwrap();
30    let mut canvas1 = Canvas::new(17,17,PixelColors::Green).unwrap();
31    canvas1.attach(&shape1,1,1).unwrap();
32    canvas1.attach(&shape2,10,10).unwrap();
33    screen1.attach(&canvas1,0,0).unwrap();
34    let mut screen2 = Screen::new(25,25,PixelColors::Green).unwrap();
35    let mut canvas2 = Canvas::new(17,17,PixelColors::Green).unwrap();
36    canvas2.attach(&shape1,1,1).unwrap();
37    canvas2.attach(&shape3,10,10).unwrap();
38    screen2.attach(&canvas2,0,0).unwrap();
39    &vecan.push(screen1);
40    &vecan.push(screen2);
41    let mut animation = Animation::new(vecan,15,10);
42    animation.play();
43
44
45}
Source

pub fn dittach(&mut self, canvas: &Canvas, x: u8, y: u8) -> Result<(), &str>

dittach removes only the cavases belongings from the screen, it works like an earaser that you point to a certain spot and it earases in a fixed manor #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors,Canvas};
 use termi_graphics::shapes::line;
 let mut screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let mut canvas1 = Canvas::new(5,5,PixelColors::Red).unwrap();
 let ln1 = line(4,PixelColors::Green,false).unwrap();
 canvas1.attach(&ln1,1,1).unwrap();
 screen1.attach(&canvas1,10,10).unwrap();
 screen1.dittach(&canvas1,10,10).unwrap();
Source

pub fn dittach_pixels( &mut self, shape: &Vec<Vec<u8>>, x: u8, y: u8, ) -> Result<(), &str>

dittach_pixels can remove a vec of pixels of the screen, again with the eareaser analogy #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors,Canvas};
 use termi_graphics::shapes::line;
 let mut screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let mut canvas1 = Canvas::new(5,5,PixelColors::Red).unwrap();
 let ln1 = line(4,PixelColors::Green,false).unwrap();
 canvas1.attach(&ln1,1,1).unwrap();
 screen1.attach(&canvas1,10,10).unwrap();
 screen1.dittach_pixels(&ln1,11,11).unwrap();

Auto Trait Implementations§

§

impl Freeze for Screen

§

impl RefUnwindSafe for Screen

§

impl Send for Screen

§

impl Sync for Screen

§

impl Unpin for Screen

§

impl UnwindSafe for Screen

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.