Start outlining a house model

This commit is contained in:
Tangent 128 2019-10-30 23:56:09 -04:00
parent 5cb3c49ed8
commit 560476ea14
3 changed files with 63 additions and 0 deletions

13
house/Cargo.lock generated Normal file
View File

@ -0,0 +1,13 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "house"
version = "0.1.0"
dependencies = [
"lights 0.1.0",
]
[[package]]
name = "lights"
version = "0.1.0"

10
house/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "house"
version = "0.1.0"
authors = ["Tangent 128 <Tangent128@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lights = { path = "../lights" }

40
house/src/lib.rs Normal file
View File

@ -0,0 +1,40 @@
#![no_std]
use lights::HardwareRgb;
use lights::gamma::correct;
use lights::Lights;
use lights::PixelIterator;
use lights::rgb::Rgb;
const PORCH_BACK_LEN: usize = 150;
const PORCH_FRONT_LEN: usize = 150;
pub struct Harrogate<PB, PF> {
pub porch_back: PB,
pub porch_front: PF,
}
impl<PB, PF> Harrogate<PB, PF>
where
PB: IntoIterator<Item = Rgb>,
PF: IntoIterator<Item = Rgb>,
{
pub fn render_to<L: Lights<Pixel = HardwareRgb>>(self, lights: &mut L) {
let mut buffer = [HardwareRgb(255,0,255); PORCH_BACK_LEN + PORCH_FRONT_LEN];
for (i, pixel) in self.porch_back.into_iter().take(PORCH_BACK_LEN).enumerate() {
buffer[PORCH_BACK_LEN - i] = correct(&pixel);
}
for (i, pixel) in self.porch_front.into_iter().take(PORCH_FRONT_LEN).enumerate() {
buffer[PORCH_BACK_LEN + i] = correct(&pixel);
}
buffer.iter().render_to(lights);
}
}
#[cfg(test)]
mod tests {
// #[test]
}