canvas: add parameter to constructor to set background color.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -21,8 +21,8 @@ pub struct Canvas {
|
||||
}
|
||||
|
||||
impl Canvas {
|
||||
pub fn new(width: usize, height: usize) -> Canvas {
|
||||
let pixels = vec![Color::new(1., 0., 1.); width * height];
|
||||
pub fn new(width: usize, height: usize, background: Color) -> Canvas {
|
||||
let pixels = vec![background; width * height];
|
||||
Canvas {
|
||||
width,
|
||||
height,
|
||||
@@ -78,7 +78,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn create_canvas() {
|
||||
let c = Canvas::new(10, 20);
|
||||
let bg = Color::new(0.0, 0.0, 0.0);
|
||||
let c = Canvas::new(10, 20, bg);
|
||||
assert_eq!(c.width, 10);
|
||||
assert_eq!(c.height, 20);
|
||||
let black = Color::new(0., 0., 0.);
|
||||
@@ -89,7 +90,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn write_to_canvas() {
|
||||
let mut c = Canvas::new(10, 20);
|
||||
let bg = Color::new(0.2, 0.2, 0.2);
|
||||
let mut c = Canvas::new(10, 20, bg);
|
||||
let red = Color::new(1., 0., 0.);
|
||||
c.set(2, 3, red);
|
||||
assert_eq!(c.get(2, 3), red);
|
||||
|
||||
Reference in New Issue
Block a user