pixel_sort/canvas/
draw.rs

1use crate::VrellisCanvas;
2use image::DynamicImage;
3use itertools::Itertools;
4
5impl VrellisCanvas {
6    pub fn draw_svg(&self) -> String {
7        format!(
8            r#"<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 {} {}">{}</svg>"#,
9            self.current_image.width(),
10            self.current_image.height(),
11            format!(
12                r#"<polyline points={:?} style="fill:none;stroke:black;stroke-width:{}"/>"#,
13                self.take_points(self.path.len()),
14                self.line_width
15            )
16        )
17    }
18    pub fn draw_svg_steps(&self) -> Vec<String> {
19        let mut out = Vec::with_capacity(self.path.len());
20        for i in 0..self.path.len() {
21            out.push(format!(
22                r#"<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 {} {}">{}</svg>"#,
23                self.current_image.width(),
24                self.current_image.height(),
25                format!(
26                    r#"<polyline points={:?} style="fill:none;stroke:black;stroke-width:{}"/>"#,
27                    self.take_points(i),
28                    self.line_width
29                )
30            ))
31        }
32        return out;
33    }
34
35    fn take_points(&self, n: usize) -> String {
36        self.path
37            .iter()
38            .take(n)
39            .map(|i| unsafe { self.points.get_unchecked(*i as usize) })
40            .map(|p| format!("{},{}", p.x, p.y))
41            .collect_vec()
42            .join(" ")
43    }
44}
45
46impl VrellisCanvas {
47    pub fn draw_image(&self) -> DynamicImage {
48        unimplemented!()
49    }
50}
51
52impl VrellisCanvas {
53    pub fn draw_canvas(&self) {
54        unimplemented!()
55    }
56}