saving images
This commit is contained in:
parent
1545cc8752
commit
27c803dd20
File diff suppressed because it is too large
Load Diff
|
|
@ -10,4 +10,6 @@ eframe = "0.29.1"
|
|||
egui = "0.29.1"
|
||||
egui-file-dialog = "0.7.0"
|
||||
egui_plot = "0.29.0"
|
||||
image = "0.25.4"
|
||||
plotters = "0.3.3"
|
||||
rand = "0.8.5"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub fn display_plot<'a>(mut circles: Vec<crate::Circle>, circle_length: &'a usiz
|
|||
|
||||
|
||||
pub fn display_gui() -> Display<'static> {
|
||||
Box::new(move |ui| {
|
||||
Box::new(move |_ui| {
|
||||
//TODO: UI (on unfocus update values)
|
||||
// Message Content input
|
||||
// start shift input
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ pub fn run() -> anyhow::Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn encode(message: &mut crate::Message, circle_length: &mut usize, output: crate::OutputMode) -> anyhow::Result<()> {
|
||||
match output {
|
||||
crate::OutputMode::Display => crate::gui::gui(message, circle_length, false),
|
||||
crate::OutputMode::Save { path } => Ok(()), //TODO: Create plot and save
|
||||
crate::OutputMode::Save { path } => save(&path, message, circle_length),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,5 +70,6 @@ pub use encoding::encrypt_message;
|
|||
pub use gui::Error;
|
||||
pub use message::Message;
|
||||
pub use plotting::plot;
|
||||
pub use plotting::save;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::f64::{self, consts::PI};
|
||||
use std::{f64::{self, consts::PI}, path::PathBuf};
|
||||
|
||||
pub fn plot(ui: &mut egui::Ui, circles: &mut Vec<crate::Circle>, num_points: &usize, line_colors: &Vec<egui::Color32>) {
|
||||
egui_plot::Plot::new("Encoded Message")
|
||||
|
|
@ -26,6 +26,39 @@ pub fn plot(ui: &mut egui::Ui, circles: &mut Vec<crate::Circle>, num_points: &us
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
pub fn save(path: &PathBuf, message: &mut crate::Message, circle_length: &usize) -> anyhow::Result<()> { //TODO: Add line_colors
|
||||
use plotters::prelude::*;
|
||||
let root = BitMapBackend::new(path, (1000,1000)).into_drawing_area();
|
||||
root.fill(&WHITE)?;
|
||||
|
||||
let mut circles = crate::encrypt_message(message, circle_length);
|
||||
let length = (circles.len() as f64) + 1.0;
|
||||
|
||||
let mut chart = ChartBuilder::on(&root)
|
||||
.margin(5)
|
||||
.build_cartesian_2d(-length..length, -length..length)?;
|
||||
|
||||
circles.iter_mut().enumerate().for_each(|(count, circle)| {
|
||||
let peak_values = match count {
|
||||
count if count % 2 == 0 => crate::circle_to_points(circle),
|
||||
_ => {
|
||||
circle.reverse();
|
||||
crate::circle_to_points(circle)
|
||||
},
|
||||
};
|
||||
|
||||
let points: Vec<(f64, f64)> = gaussian_distribution(circle_length, &peak_values, &(count as f64)).points().iter()
|
||||
.map(|point| {
|
||||
(point.x, point.y)
|
||||
}).collect();
|
||||
|
||||
chart.draw_series(LineSeries::new(points, &RED)).unwrap();
|
||||
});
|
||||
root.present()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn gaussian_distribution(num_points: &usize, peak_values: &Vec<f64>, offset: &f64) -> egui_plot::PlotPoints {
|
||||
let mut radii: Vec<f64> = vec![1.0; *num_points];
|
||||
let num_peaks = peak_values.len();
|
||||
|
|
|
|||
Loading…
Reference in New Issue