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
impl Canvas
Sourcepub fn paint<T, N>(&mut self, target: &T, x: N, y: N) -> Result<(), RsilleErr>
pub fn paint<T, N>(&mut self, target: &T, x: N, y: N) -> Result<(), RsilleErr>
Paint those Paint object on the location (x, y)
Sourcepub fn print(&self)
pub fn print(&self)
Print the canvas to the terminal
If you want to print the canvas to a buffer, use the print_on
Sourcepub fn print_on<W>(&self, w: &mut W, is_raw: bool) -> Result<(), RsilleErr>where
W: Write,
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
Sourcepub fn clear(&mut self)
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
Sourcepub fn set_size<T>(&mut self, width: T, height: T)
pub fn set_size<T>(&mut self, width: T, height: T)
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.
Sourcepub fn set_minx<T>(&mut self, minx: T)
pub fn set_minx<T>(&mut self, minx: T)
Set the min x of th canvas
In most time, no need to call this, only when the animation is moved when running
Sourcepub fn set_maxy<T>(&mut self, maxy: T)
pub fn set_maxy<T>(&mut self, maxy: T)
Set the max y of the canvas
In most time, no need to call this, only when the animation is moved when running
Sourcepub fn set<T>(&mut self, x: T, y: T)
pub fn set<T>(&mut self, x: T, y: T)
Draw a dot on (x, y)
Just use the (x, y) in your object, the algorithm will find the right location
Sourcepub fn set_colorful<T>(&mut self, x: T, y: T, color: Color)
pub fn set_colorful<T>(&mut self, x: T, y: T, color: Color)
Similar to set
But it’s support color
Sourcepub fn toggle<T>(&mut self, x: T, y: T)
pub fn toggle<T>(&mut self, x: T, y: T)
If the (x, y) is already set, then unset it
If the (x, y) is unset, then set it
Sourcepub fn line<T>(&mut self, xy1: (T, T), xy2: (T, T))
pub fn line<T>(&mut self, xy1: (T, T), xy2: (T, T))
Draw a line on the canvas
xy1- the start locationxy2- the end location
Sourcepub fn line_any<T>(
&mut self,
xy1: (T, T),
xy2: (T, T),
c: char,
color: Option<Color>,
)
pub fn line_any<T>( &mut self, xy1: (T, T), xy2: (T, T), c: char, color: Option<Color>, )
Draw a line on the canvas
xy1- the start locationxy2- the end locationc- the char used in linecolor- 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!
Sourcepub fn line_colorful<T>(&mut self, xy1: (T, T), xy2: (T, T), color: Color)
pub fn line_colorful<T>(&mut self, xy1: (T, T), xy2: (T, T), color: Color)
Draw a line on the canvas with the color
xy1- the start locationxy2- the end location