add screenshotting
This commit is contained in:
69
src/main.rs
69
src/main.rs
@@ -1,13 +1,16 @@
|
||||
#![feature(random)]
|
||||
use core::f32;
|
||||
use std::{
|
||||
fs::read_dir,
|
||||
fs::{read_dir, OpenOptions},
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
process::{Command, Stdio},
|
||||
sync::mpsc::{self, Receiver, Sender},
|
||||
thread::{self, JoinHandle},
|
||||
time::Duration,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use chrono::{Datelike, Local, Timelike};
|
||||
use macroquad::prelude::*;
|
||||
|
||||
const THICKNESS: f32 = 2.0;
|
||||
@@ -19,10 +22,15 @@ static mut PORT: Option<String> = None;
|
||||
struct Point {
|
||||
x: f32,
|
||||
y: f32,
|
||||
time_since_last: f32,
|
||||
}
|
||||
impl Point {
|
||||
fn new(x: f32, y: f32) -> Self {
|
||||
Self { x, y }
|
||||
fn new(x: f32, y: f32, delta: f32) -> Self {
|
||||
Self {
|
||||
x,
|
||||
y,
|
||||
time_since_last: delta,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +111,7 @@ impl<'a> Graph<'a> {
|
||||
Self {
|
||||
font,
|
||||
// start all the dots off screen
|
||||
points: [Point::new(-1., -1.); TAIL_LEN],
|
||||
points: [Point::new(-1., -1., 0.); TAIL_LEN],
|
||||
head: 0,
|
||||
axises,
|
||||
x_origin: x_offset,
|
||||
@@ -176,6 +184,7 @@ impl<'a> Graph<'a> {
|
||||
self.push(Point::new(
|
||||
self.head_tracker,
|
||||
self.y_origin - y_displacement,
|
||||
delta_time,
|
||||
));
|
||||
}
|
||||
Axis::Two => {
|
||||
@@ -183,6 +192,7 @@ impl<'a> Graph<'a> {
|
||||
self.push(Point::new(
|
||||
self.x_origin + x_displacement,
|
||||
self.y_origin - y_displacement,
|
||||
delta_time,
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -339,12 +349,55 @@ async fn main() {
|
||||
|
||||
graph.draw();
|
||||
|
||||
if is_key_pressed(KeyCode::F3) {
|
||||
show_debug = !show_debug;
|
||||
}
|
||||
if is_key_pressed(KeyCode::F1) {
|
||||
pause = !pause;
|
||||
}
|
||||
if is_key_pressed(KeyCode::F2) {
|
||||
// Dump data to csv
|
||||
if let Ok(mut file) = OpenOptions::new()
|
||||
.write(true)
|
||||
.append(false)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open("data.csv")
|
||||
{
|
||||
let mut x = 0.;
|
||||
for p in &graph.points {
|
||||
x += p.time_since_last;
|
||||
let _ = file.write_all(format!("{x},{}\n", p.y).as_bytes());
|
||||
}
|
||||
let _ = file.flush();
|
||||
|
||||
let now = Local::now();
|
||||
let date_string = format!(
|
||||
"{}-{}-{}-{}-{}-{}-{}",
|
||||
now.year(),
|
||||
now.month(),
|
||||
now.day(),
|
||||
now.hour(),
|
||||
now.minute(),
|
||||
now.second(),
|
||||
now.timestamp_subsec_millis()
|
||||
);
|
||||
|
||||
if let Ok(out_file) = OpenOptions::new()
|
||||
.write(true)
|
||||
.append(false)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(format!("dump-{date_string}.png"))
|
||||
{
|
||||
let _ = Command::new("gnuplot")
|
||||
.stdin(file)
|
||||
.arg("template.gnuplot")
|
||||
.stdout(out_file)
|
||||
.spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_key_pressed(KeyCode::F3) {
|
||||
show_debug = !show_debug;
|
||||
}
|
||||
|
||||
let (_, my) = mouse_wheel();
|
||||
graph.px_per_s += 10. * my;
|
||||
|
||||
Reference in New Issue
Block a user