thin_arrows/
thin-arrows.rs1use std::f64::consts::TAU;
2use std::path::Path;
3
4use plotters::prelude::*;
5use plotters_arrows::ThinArrow;
6
7fn main() -> Result<(), DrawingAreaErrorKind<<BitMapBackend<'static> as DrawingBackend>::ErrorType>>
8{
9 let target = Path::new("example.png");
10 let graph_root = BitMapBackend::new(target, (256, 256)).into_drawing_area();
11 graph_root.fill(&WHITE)?;
12 let mut chart = ChartBuilder::on(&graph_root)
13 .margin(8)
14 .x_label_area_size(24)
15 .y_label_area_size(24)
16 .build_cartesian_2d(0f64..1f64, 0f64..1f64)?;
17
18 chart.configure_mesh().draw()?;
19
20 let x_count = 16;
21 let y_count = 16;
22 let arrow_size = 0.05;
23 chart.draw_series(
24 (0..=x_count)
25 .flat_map(|xi| (0..=y_count).map(move |yi| (xi, yi)))
26 .map(|(xi, yi)| {
27 let x = xi as f64 / x_count as f64;
28 let y = yi as f64 / y_count as f64;
29 let dx = arrow_size * f64::cos(y * TAU);
30 let dy = arrow_size * f64::cos(x * TAU);
31 ThinArrow::new((x, y), (x + dx, y + dy), &RED)
32 }),
33 )?;
34
35 graph_root.present()?;
36
37 Ok(())
38}