list of transformers
This commit is contained in:
parent
de26c1c793
commit
9844475fa1
28
src/main.rs
28
src/main.rs
@ -21,7 +21,7 @@ use redis_ctrl::{RedisCtrl,Order};
|
|||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::{LJError,LJResult};
|
use errors::{LJError,LJResult};
|
||||||
use point::Point;
|
use point::Point;
|
||||||
use modifier::{Transformers,Translate};
|
use modifier::{Transformers,Translate,Replicate};
|
||||||
|
|
||||||
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
||||||
|
|
||||||
@ -48,14 +48,19 @@ fn run_all() -> LJResult<()> {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut device = get_helios_device()?;
|
let mut device = get_helios_device()?;
|
||||||
|
|
||||||
|
let transformers : Vec<Box<dyn Transformers>> = vec![
|
||||||
|
Box::new(Translate::new(CENTER.0, CENTER.1)),
|
||||||
|
Box::new(Replicate::Until(48))
|
||||||
|
];
|
||||||
|
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
let order = rs.get_order(config.laser_id)?;
|
let order = rs.get_order(config.laser_id)?;
|
||||||
if order != Order::Draw {
|
if order != Order::Draw {
|
||||||
println!("{:?}", order);
|
println!("{:?}", order);
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = get_next_frame(&config, 1000,
|
let frame = get_next_frame(&config, 1000, &transformers,
|
||||||
&mut rs, order == Order::Black)?;
|
&mut rs, order == Order::Black)?;
|
||||||
|
|
||||||
while let Ok(DeviceStatus::NotReady) = device.status() {
|
while let Ok(DeviceStatus::NotReady) = device.status() {
|
||||||
@ -81,23 +86,20 @@ fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
|||||||
fn get_next_frame(
|
fn get_next_frame(
|
||||||
config: &Conf,
|
config: &Conf,
|
||||||
speed: u32,
|
speed: u32,
|
||||||
|
transformers: &[Box<dyn Transformers>],
|
||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
_black: bool
|
_black: bool
|
||||||
) -> LJResult<Frame> {
|
) -> LJResult<Frame> {
|
||||||
|
|
||||||
|
|
||||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||||
let line: Vec<Point> = line.into_iter().map(| tpl | tpl.into()).collect();
|
let mut line: Vec<Point> = line.into_iter().map(| tpl | tpl.into()).collect();
|
||||||
let line = Translate::new(CENTER.0, CENTER.1).apply(&line);
|
for transformer in transformers {
|
||||||
|
line = transformer.apply(&line);
|
||||||
let mut line2 = vec![];
|
|
||||||
while line2.len() < 48 {
|
|
||||||
for p in &line {
|
|
||||||
line2.push(*p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:?}", line2);
|
println!("{:?}", line);
|
||||||
|
|
||||||
let line2 : Vec<helios_dac::Point> = line2.into_iter().map(| p | p.into()).collect();
|
let line2 : Vec<helios_dac::Point> = line.into_iter().map(| p | p.into()).collect();
|
||||||
Ok(Frame::new(speed, line2))
|
Ok(Frame::new(speed, line2))
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ pub trait Transformers {
|
|||||||
fn apply(&self, point_list: &Vec<Point>) -> Vec<Point>;
|
fn apply(&self, point_list: &Vec<Point>) -> Vec<Point>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translate
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy)]
|
#[derive(Debug,Clone,Copy)]
|
||||||
pub struct Translate {
|
pub struct Translate {
|
||||||
x: f32,
|
x: f32,
|
||||||
@ -27,3 +29,31 @@ impl Transformers for Translate {
|
|||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replicate
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Copy)]
|
||||||
|
pub enum Replicate {
|
||||||
|
Until(usize),
|
||||||
|
Times(usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transformers for Replicate {
|
||||||
|
fn apply(&self, point_list: &Vec<Point>) -> Vec<Point> {
|
||||||
|
let mut point_list2 = vec![];
|
||||||
|
match self {
|
||||||
|
Replicate::Until(n) => {
|
||||||
|
while point_list2.len() < *n {
|
||||||
|
point_list2.append(&mut point_list.clone());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Replicate::Times(n) => {
|
||||||
|
for _ in 0..*n {
|
||||||
|
point_list2.append(&mut point_list.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
point_list2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user