cleanup and new grid
This commit is contained in:
parent
81de6728fc
commit
9a5db444a0
19
src/conf.rs
19
src/conf.rs
@ -36,7 +36,16 @@ pub enum TransformConf {
|
|||||||
#[serde(rename = "translate")]
|
#[serde(rename = "translate")]
|
||||||
Translate(transformer::Translate),
|
Translate(transformer::Translate),
|
||||||
#[serde(rename = "replicate")]
|
#[serde(rename = "replicate")]
|
||||||
Replicate(transformer::Replicate)
|
Replicate(transformer::Replicate),
|
||||||
|
#[serde(rename = "rotate")]
|
||||||
|
Rotate(transformer::Rotate),
|
||||||
|
#[serde(rename = "flip_horizontal")]
|
||||||
|
FlipH(transformer::FlipHorizontal),
|
||||||
|
#[serde(rename = "flip_vertical")]
|
||||||
|
FlipV(transformer::FlipVertical),
|
||||||
|
#[serde(rename = "grid")]
|
||||||
|
Grid(transformer::Grid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +64,11 @@ impl Conf {
|
|||||||
for t in &self.transformers {
|
for t in &self.transformers {
|
||||||
let t : Box<dyn transformer::Transformers> = match t {
|
let t : Box<dyn transformer::Transformers> = match t {
|
||||||
TransformConf::Translate(t) => Box::new(*t),
|
TransformConf::Translate(t) => Box::new(*t),
|
||||||
TransformConf::Replicate(r) => Box::new(*r)
|
TransformConf::Replicate(r) => Box::new(*r),
|
||||||
|
TransformConf::Rotate(r) => Box::new(*r),
|
||||||
|
TransformConf::FlipH(r) => Box::new(*r),
|
||||||
|
TransformConf::FlipV(r) => Box::new(*r),
|
||||||
|
TransformConf::Grid(r) => Box::new(*r)
|
||||||
};
|
};
|
||||||
v.push(t);
|
v.push(t);
|
||||||
}
|
}
|
||||||
@ -69,7 +82,7 @@ impl Conf {
|
|||||||
redis_url: "redis://127.0.0.1:6379/".to_string(),
|
redis_url: "redis://127.0.0.1:6379/".to_string(),
|
||||||
dac: DacFamily::Helios(HeliosConf { id: 0 }),
|
dac: DacFamily::Helios(HeliosConf { id: 0 }),
|
||||||
transformers: vec![
|
transformers: vec![
|
||||||
TransformConf::Translate(transformer::Translate::new(2000.0,2000.0)),
|
TransformConf::Translate(transformer::Translate { x: 2000.0, y: 2000.0 } ),
|
||||||
TransformConf::Replicate(transformer::Replicate::Until(48))
|
TransformConf::Replicate(transformer::Replicate::Until(48))
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -73,7 +73,7 @@ fn run_all() -> LJResult<()> {
|
|||||||
let frame = get_next_frame(&config, &transformers,
|
let frame = get_next_frame(&config, &transformers,
|
||||||
&mut rs, order == Order::Black)?;
|
&mut rs, order == Order::Black)?;
|
||||||
// For now, draw all the time
|
// For now, draw all the time
|
||||||
tracer.draw(frame, 40_000)?;
|
tracer.draw(frame, 2_000)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Exiting, stoping device.");
|
info!("Exiting, stoping device.");
|
||||||
@ -102,8 +102,11 @@ fn get_next_frame(
|
|||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
_black: bool,
|
_black: bool,
|
||||||
) -> LJResult<Vec<Point>> {
|
) -> LJResult<Vec<Point>> {
|
||||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
//let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||||
|
let line = vec![(300.0,200.0,0),(500.0,200.0,65280),(500.0,400.0,65280),(300.0,400.0,65280),(300.0,200.0,65280),(300.0,200.0,0),(200.0,100.0,0),(600.0,100.0,65280),(600.0,500.0,65280),(200.0,500.0,65280),(200.0,100.0,65280)];
|
||||||
|
|
||||||
let mut line: Vec<Point> = line.into_iter().map(|tpl| tpl.into()).collect();
|
let mut line: Vec<Point> = line.into_iter().map(|tpl| tpl.into()).collect();
|
||||||
|
|
||||||
for transformer in transformers {
|
for transformer in transformers {
|
||||||
line = transformer.apply(&line);
|
line = transformer.apply(&line);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ mod replicate;
|
|||||||
mod rotate;
|
mod rotate;
|
||||||
mod flip_horizontal;
|
mod flip_horizontal;
|
||||||
mod flip_vertical;
|
mod flip_vertical;
|
||||||
|
mod grid;
|
||||||
|
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ pub use replicate::Replicate;
|
|||||||
pub use rotate::Rotate;
|
pub use rotate::Rotate;
|
||||||
pub use flip_horizontal::FlipHorizontal;
|
pub use flip_horizontal::FlipHorizontal;
|
||||||
pub use flip_vertical::FlipVertical;
|
pub use flip_vertical::FlipVertical;
|
||||||
|
pub use grid::Grid;
|
||||||
|
|
||||||
pub trait Transformers {
|
pub trait Transformers {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
||||||
|
@ -9,12 +9,6 @@ pub struct FlipHorizontal {
|
|||||||
x: f32,
|
x: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlipHorizontal {
|
|
||||||
pub fn new(x: f32) -> Self {
|
|
||||||
Self {x}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for FlipHorizontal {
|
impl Transformers for FlipHorizontal {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
||||||
point_list.iter()
|
point_list.iter()
|
||||||
|
@ -9,12 +9,6 @@ pub struct FlipVertical {
|
|||||||
y: f32,
|
y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlipVertical {
|
|
||||||
pub fn new(y: f32) -> Self {
|
|
||||||
Self {y}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for FlipVertical {
|
impl Transformers for FlipVertical {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
||||||
point_list.iter()
|
point_list.iter()
|
||||||
|
56
src/transformer/grid.rs
Normal file
56
src/transformer/grid.rs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
use crate::transformer::Transformers;
|
||||||
|
use crate::point::Point;
|
||||||
|
use serde::{Serialize,Deserialize};
|
||||||
|
|
||||||
|
/// Translate
|
||||||
|
|
||||||
|
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
||||||
|
pub struct Grid {
|
||||||
|
width: f32,
|
||||||
|
height: f32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn square_box(size: f32, color: u32) -> Vec<(f32, f32, u32)> {
|
||||||
|
vec![
|
||||||
|
(-size, -size, 0),
|
||||||
|
(-size, -size, color),
|
||||||
|
|
||||||
|
(0.0, -size, color),
|
||||||
|
(0.0, -size, color),
|
||||||
|
|
||||||
|
(size, -size, color),
|
||||||
|
(size, -size, color),
|
||||||
|
|
||||||
|
(size, 0.0, color),
|
||||||
|
(size, 0.0, color),
|
||||||
|
|
||||||
|
(size, size, color),
|
||||||
|
(size, size, color),
|
||||||
|
|
||||||
|
(0.0, size, color),
|
||||||
|
(0.0, size, color),
|
||||||
|
|
||||||
|
(-size, size, color),
|
||||||
|
(-size, size, color),
|
||||||
|
|
||||||
|
(-size, 0.0, color),
|
||||||
|
(-size, 0.0, color),
|
||||||
|
|
||||||
|
(-size, -size, color),
|
||||||
|
(-size, -size, color),
|
||||||
|
|
||||||
|
(-size, -size, 0)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transformers for Grid {
|
||||||
|
fn apply(&self, _point_list: &[Point]) -> Vec<Point> {
|
||||||
|
let mut sq1 = square_box(1000.0, 255 << 8);
|
||||||
|
let mut line = square_box(2000.0, 255);
|
||||||
|
line.append(&mut sq1);
|
||||||
|
|
||||||
|
let line: Vec<Point> = line.into_iter()
|
||||||
|
.map(|tpl| tpl.into()).collect();
|
||||||
|
line
|
||||||
|
}
|
||||||
|
}
|
@ -13,12 +13,6 @@ pub struct Rotate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rotate {
|
|
||||||
pub fn new(cx: f32, cy: f32, angle: f32) -> Self {
|
|
||||||
Self { cx, cy, angle: angle / 180. * PI}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for Rotate {
|
impl Transformers for Rotate {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
||||||
point_list.iter()
|
point_list.iter()
|
||||||
|
@ -6,14 +6,8 @@ use serde::{Serialize,Deserialize};
|
|||||||
|
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
||||||
pub struct Translate {
|
pub struct Translate {
|
||||||
x: f32,
|
pub x: f32,
|
||||||
y: f32
|
pub y: f32
|
||||||
}
|
|
||||||
|
|
||||||
impl Translate {
|
|
||||||
pub fn new(x: f32, y: f32) -> Self {
|
|
||||||
Self { x, y }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for Translate {
|
impl Transformers for Translate {
|
||||||
|
Loading…
Reference in New Issue
Block a user