Adding support for polylines, wind and cog
This commit is contained in:
39
src/forms.rs
39
src/forms.rs
@@ -37,9 +37,22 @@ impl Screen {
|
||||
let tx_points = form.points.iter().map(|p| transform.transform_point(*p)).collect::<Vec<_>>();
|
||||
let screen_points = tx_points.iter().map(|p| self.model_scale.transform_point(*p)).collect::<Vec<_>>();
|
||||
for (indices, weight, (r, g, b)) in &form.lines {
|
||||
let mut indices_i = indices.into_iter();
|
||||
let mut last = indices_i.next();
|
||||
while last.is_some() {
|
||||
let mut pn = indices_i.next();
|
||||
if pn.is_some() {
|
||||
let p0 = screen_points[*last.unwrap() as usize].to_tuple();
|
||||
let p1 = screen_points[*pn.unwrap() as usize].to_tuple();
|
||||
draw_line_segment_mut(&mut self.image, p0, p1, Rgb([*r, *g, *b]));
|
||||
}
|
||||
last = pn;
|
||||
}
|
||||
/*
|
||||
let p0 = screen_points[indices[0] as usize].to_tuple();
|
||||
let p1 = screen_points[indices[1] as usize].to_tuple();
|
||||
draw_line_segment_mut(&mut self.image, p0, p1, Rgb([*r, *g, *b]));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +114,23 @@ impl Form {
|
||||
points.push(Point2D::new(pp[2]-500.0, pp[3]-500.0));
|
||||
|
||||
lines.push((vec![points_id, points_id+1], width, (r,g,b)));
|
||||
} else
|
||||
if name.local_name == "polyline" {
|
||||
let mut points_str: String = "".to_string();
|
||||
let mut width = 1;
|
||||
let (mut r, mut g, mut b): (u8, u8, u8) = (255,255,255);
|
||||
for i in attributes {
|
||||
match i.name.local_name.as_str() {
|
||||
"points" => points_str = i.value,
|
||||
"stroke" => scan!(i.value.bytes() => "rgb({},{},{})", r, g, b),
|
||||
"stroke-width" => width = u8::from_str(&i.value)?,
|
||||
_ => println!("unhandled attribute {}", i.name.local_name),
|
||||
}
|
||||
}
|
||||
let mut coords = points_str.split(" ").into_iter().map(|s| -> Point2D<f32, ModelSpace> { let x: f32; let y: f32; scan!(s.bytes() => "{},{}",x,y); Point2D::new(x-500.0,y-500.0) }).collect::<Vec<_>>();
|
||||
let indices = (0..coords.len()).into_iter().map(|x| -> (u16) { (x+points.len()) as u16 }).collect::<Vec<_>>();
|
||||
points.append(&mut coords);
|
||||
lines.push((indices, width, (r,g,b)));
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
@@ -126,3 +156,12 @@ pub fn load_boat () -> Form {
|
||||
form
|
||||
}
|
||||
|
||||
pub fn load_cog () -> Form {
|
||||
let form = Form::load("/root/forms/cog.svg").unwrap();
|
||||
form
|
||||
}
|
||||
|
||||
pub fn load_wind () -> Form {
|
||||
let form = Form::load("/root/forms/wind.svg").unwrap();
|
||||
form
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut screen = forms::Screen::new(200, 200);
|
||||
let c = forms::load_compass_rose();
|
||||
let b = forms::load_boat();
|
||||
let cog = forms::load_cog();
|
||||
let wind = forms::load_wind();
|
||||
|
||||
/*
|
||||
let mut img = RgbImage::new(480, 320);
|
||||
@@ -33,13 +35,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut e = ilidisplay::IliDisplay::init()?;
|
||||
e.init_chip();
|
||||
e.turn_on();
|
||||
for i in 0..100 {
|
||||
for i in 0..10 {
|
||||
let rad = (i as f32) * 2.0*PI / 100.0;
|
||||
screen.clear();
|
||||
screen.render(&cog, -rad*2.0, 500, 500);
|
||||
screen.render(&wind, rad*2.0, 500, 500);
|
||||
screen.render(&c, rad, 500, 500);
|
||||
screen.render(&b, 0.0, 500, 500);
|
||||
e.put_image(&(screen.image), ((240-100), (160-100)));
|
||||
}
|
||||
screen.save();
|
||||
|
||||
// draw_filled_rect_mut(&mut img, Rect::at(0,0).of_size(480, 320), Rgb([0, 0, 0]));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user