Can create canvas

This commit is contained in:
Jon Janzen
2021-02-19 19:58:52 -07:00
parent 5232e69ec1
commit 1fc84c7d1f
4 changed files with 87 additions and 2 deletions

36
canvas/src/lib.rs Normal file
View File

@@ -0,0 +1,36 @@
use color::Color;
struct Canvas {
width: usize,
height: usize,
pixels: Vec<Vec<Color>>,
}
impl Canvas {
fn new(width: usize, height: usize) -> Canvas {
Canvas {
width,
height,
pixels : vec![vec![Color::new(0.0, 0.0, 0.0); width]; height],
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn create_canvas() {
let c = Canvas::new(10, 20);
assert_eq!(10, c.width);
assert_eq!(20, c.height);
let black = Color::new(0.0, 0.0, 0.0);
for row in c.pixels {
for pixel in row {
assert_eq!(black, pixel);
}
}
}
}