Animation

Struct Animation 

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

animation struct is used to connect between different screens and run them in a fixed speed.

Implementations§

Source§

impl Animation

Source

pub fn new(roll: Vec<Screen>, fps: u8, length: u8) -> Animation

defines a new animation #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors};
 use termi_graphics::animation::Animation;
 let screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen2 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen3 = Screen::new(25,25,PixelColors::Red).unwrap();
 let anim = Animation::new(vec![screen1,screen2,screen3],15,10);

creates a new animation made of 3 reoccuring screen running at 15 fps for 10 seconds.

Examples found in repository?
examples/shapes/main.rs (line 39)
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 41)
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 play(&self)

starts the animation #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors};
 use termi_graphics::animation::Animation;
 let screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen2 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen3 = Screen::new(25,25,PixelColors::Red).unwrap();
 let anim = Animation::new(vec![screen1,screen2,screen3],15,10);
 anim.play();

running the 3 screen one after the other in rate of 15 screens per sec, for 10 seconds, then stops.

Examples found in repository?
examples/shapes/main.rs (line 40)
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 42)
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 pause(&self)

stops animation doesn’t work well just yet - making threadpools in upcoming changes #Examples

 use termi_graphics::pixel_art::{Screen,PixelColors};
 use termi_graphics::animation::Animation;
 let screen1 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen2 = Screen::new(25,25,PixelColors::Red).unwrap();
 let screen3 = Screen::new(25,25,PixelColors::Red).unwrap();
 let anim = Animation::new(vec![screen1,screen2,screen3],15,10);
 anim.play();
 anim.pause();

Auto Trait Implementations§

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.