Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
890 B
3
Indexable
Never

struct Matrix
{
    wsize: usize,
    hsize: usize,
    wnumber: usize,
    hnumber: usize,
    colors: Vec<(u8,u8,u8)>, // will be accessed by colors[i*hnumber + j] 
                             // for colors[i][j] with i abscisse, j ordonnee
}

impl Matrix
{
    pub fn new(wsize: usize, hsize: usize, wnumber: usize, hnumber: usize, default_color: (u8,u8,u8)) -> Self
    {
        Matrix {
            wsize: wsize,
            hsize: hsize,
            wnumber: wnumber,
            hnumber: hnumber,
            colors: vec![default_color; wnumber*hnumber],
        }
    }

    pub fn map(self: Self, closure:P) -> Self
        where P: Fn((u8,u8,u8)) -> (u8,u8,u8), 
    {
        Matrix::new(self.wsize, self.hsize, self.wnumber, self.hnumber,
                    self.colors.iter().map::<(u8,u8,u8),P>(closure).collect())
    }
}

pub fn main()
{
    println!("Hello there !");
}