Canvas

Struct Canvas 

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

The basic canvas

Paint anything on the canvas anywhere you want. Don’t worry about the (x, y), the size of canvas will auto increase, and it support the negative number.

§Example

Draw the y = 1.5*sin(x) and y = cos(x)

use rsille::Canvas;
let mut c = Canvas::new();
for x in 0..1000 {
    let x = x as f64;
    c.set(x / 10.0, x.to_radians().sin() * 15.0);
    c.set(x / 10.0, x.to_radians().cos() * 10.0);
}
c.print();

§NOTE

Take a look at the extra module, there are some useful things can paint on the canvas

Implementations§

Source§

impl Canvas

Source

pub fn new() -> Self

Make a new empty canvas

The size of the canvas will auto increase

Source

pub fn paint<T, N>(&mut self, target: &T, x: N, y: N) -> Result<(), RsilleErr>
where T: Paint, N: Into<f64>,

Paint those Paint object on the location (x, y)

Source

pub fn print(&self)

Print the canvas to the terminal

If you want to print the canvas to a buffer, use the print_on

Source

pub fn print_on<W>(&self, w: &mut W, is_raw: bool) -> Result<(), RsilleErr>
where W: Write,

Print the canvas to the buffer

If you want to print the canvas to the terminal, use the print

Source

pub fn clear(&mut self)

Clear the canvas

This method only clear those dots on the canvas, the size of the canvas will not change If you want to clear the size too, use the reset

Source

pub fn reset(&mut self)

Reset the canvas to a new empty canvas

Source

pub fn set_size<T>(&mut self, width: T, height: T)
where T: Into<f64>,

Set the size of the canvas

This method can’t fix the size of the canvas, it’s just set the canvas size. When the size isn’t enough, the canvas will auto increase. And the (width, height) isn’t the size of the terminal, it’s the size of the canvas! For example, an object x from -30 to 30, then it’s 60 in width. On the terminal, it’s 30 in width(because braille code), but you should set the width to 60 not 30.

Source

pub fn set_minx<T>(&mut self, minx: T)
where T: Into<f64>,

Set the min x of th canvas

In most time, no need to call this, only when the animation is moved when running

Source

pub fn set_maxy<T>(&mut self, maxy: T)
where T: Into<f64> + Copy,

Set the max y of the canvas

In most time, no need to call this, only when the animation is moved when running

Source

pub fn set<T>(&mut self, x: T, y: T)
where T: Into<f64> + Copy,

Draw a dot on (x, y)

Just use the (x, y) in your object, the algorithm will find the right location

Source

pub fn set_colorful<T>(&mut self, x: T, y: T, color: Color)
where T: Into<f64> + Copy,

Similar to set

But it’s support color

Source

pub fn toggle<T>(&mut self, x: T, y: T)
where T: Into<f64> + Copy,

If the (x, y) is already set, then unset it

If the (x, y) is unset, then set it

Source

pub fn line<T>(&mut self, xy1: (T, T), xy2: (T, T))
where T: Into<f64>,

Draw a line on the canvas

  • xy1 - the start location
  • xy2 - the end location
Source

pub fn line_any<T>( &mut self, xy1: (T, T), xy2: (T, T), c: char, color: Option<Color>, )
where T: Into<f64>,

Draw a line on the canvas

  • xy1 - the start location
  • xy2 - the end location
  • c - the char used in line
  • color - optional, the color

It can draw any character on canvas, and when there are both a braille code and any char on (x, y), the character will cover the braille code!

Source

pub fn line_colorful<T>(&mut self, xy1: (T, T), xy2: (T, T), color: Color)
where T: Into<f64> + Copy,

Draw a line on the canvas with the color

  • xy1 - the start location
  • xy2 - the end location
Source

pub fn put_text<T>(&mut self, x: T, y: T, text: &str, color: Option<Color>)
where T: Into<f64>,

Put text on canvas

It can draw any character on canvas, and when there are both a braille code and any char on (x, y), the character will cover the braille code!

Source

pub fn put<T>(&mut self, x: T, y: T, c: char, color: Option<Color>)
where T: Into<f64>,

Put char on canvas

It can draw any character on canvas, and when there are both a braille code and any char on (x, y), the character will cover the braille code!

Trait Implementations§

Source§

impl Clone for Canvas

Source§

fn clone(&self) -> Canvas

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Canvas

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Canvas

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Canvas

§

impl RefUnwindSafe for Canvas

§

impl Send for Canvas

§

impl Sync for Canvas

§

impl Unpin for Canvas

§

impl UnwindSafe for Canvas

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.