Can create canvas
This commit is contained in:
39
canvas/Cargo.lock
generated
Normal file
39
canvas/Cargo.lock
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "canvas"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"color",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"approx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
10
canvas/Cargo.toml
Normal file
10
canvas/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "canvas"
|
||||
version = "0.1.0"
|
||||
authors = ["Jon Janzen <jonjanzen@me.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
color = { path = "../color" }
|
||||
36
canvas/src/lib.rs
Normal file
36
canvas/src/lib.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user