Struct Raster

Source
pub struct Raster { /* private fields */ }

Implementations§

Source§

impl Raster

Source

pub fn new(w: usize, h: usize) -> Raster

Examples found in repository?
examples/draw_shape.rs (line 64)
61fn main() {
62    let w = 400;
63    let h = 400;
64    let mut r = Raster::new(w, h);
65    draw_shape(&mut r, 4.0);
66    let mut o = stdout();
67    let _ = o.write(format!("P5\n{} {}\n255\n", w, h).as_bytes());
68    let _ = o.write(&r.get_bitmap());
69}
Source

pub fn draw_line(&mut self, p0: &Point, p1: &Point)

Examples found in repository?
examples/draw_shape.rs (lines 25-34)
24fn draw_shape(r: &mut Raster, s: f32) {
25    r.draw_line(
26        &Point {
27            x: s * 10.0,
28            y: s * 10.5,
29        },
30        &Point {
31            x: s * 20.0,
32            y: s * 150.0,
33        },
34    );
35    r.draw_line(
36        &Point {
37            x: s * 20.0,
38            y: s * 150.0,
39        },
40        &Point {
41            x: s * 50.0,
42            y: s * 139.0,
43        },
44    );
45    r.draw_quad(
46        &Point {
47            x: s * 50.0,
48            y: s * 139.0,
49        },
50        &Point {
51            x: s * 100.0,
52            y: s * 60.0,
53        },
54        &Point {
55            x: s * 10.0,
56            y: s * 10.5,
57        },
58    );
59}
Source

pub fn draw_quad(&mut self, p0: &Point, p1: &Point, p2: &Point)

Examples found in repository?
examples/draw_shape.rs (lines 45-58)
24fn draw_shape(r: &mut Raster, s: f32) {
25    r.draw_line(
26        &Point {
27            x: s * 10.0,
28            y: s * 10.5,
29        },
30        &Point {
31            x: s * 20.0,
32            y: s * 150.0,
33        },
34    );
35    r.draw_line(
36        &Point {
37            x: s * 20.0,
38            y: s * 150.0,
39        },
40        &Point {
41            x: s * 50.0,
42            y: s * 139.0,
43        },
44    );
45    r.draw_quad(
46        &Point {
47            x: s * 50.0,
48            y: s * 139.0,
49        },
50        &Point {
51            x: s * 100.0,
52            y: s * 60.0,
53        },
54        &Point {
55            x: s * 10.0,
56            y: s * 10.5,
57        },
58    );
59}
Source

pub fn get_bitmap(&self) -> Vec<u8>

Examples found in repository?
examples/draw_shape.rs (line 68)
61fn main() {
62    let w = 400;
63    let h = 400;
64    let mut r = Raster::new(w, h);
65    draw_shape(&mut r, 4.0);
66    let mut o = stdout();
67    let _ = o.write(format!("P5\n{} {}\n255\n", w, h).as_bytes());
68    let _ = o.write(&r.get_bitmap());
69}

Auto Trait Implementations§

§

impl Freeze for Raster

§

impl RefUnwindSafe for Raster

§

impl Send for Raster

§

impl Sync for Raster

§

impl Unpin for Raster

§

impl UnwindSafe for Raster

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.