diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-01 23:19:19 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-01 23:19:19 +0200 |
commit | 6ae973130eca4482e7048e55cd0aeb447533c296 (patch) | |
tree | f3007da29b9d81745a4e500e577e081d59e3f84b /src/main.rs | |
download | oscosu-6ae973130eca4482e7048e55cd0aeb447533c296.tar oscosu-6ae973130eca4482e7048e55cd0aeb447533c296.tar.bz2 oscosu-6ae973130eca4482e7048e55cd0aeb447533c296.tar.zst |
a
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6e9f760 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,61 @@ +use std::{ + env::args, + f32::consts::PI, + fs::read_to_string, + io::{BufWriter, Write, stdout}, + time::Instant, +}; + +fn main() { + let mut out = BufWriter::new(stdout()); + let objects = parse_file(&read_to_string(&args().nth(1).unwrap()).unwrap()); + + let start = Instant::now(); + loop { + let time = start.elapsed().as_secs_f32(); + let mut points = Vec::new(); + + for h in &objects { + let t = h.time as f32 / 1000.; + let trel = time - t; + if trel > 0. || trel < -1. { + continue; + } + let x = h.x as f32 / 512.; + let y = h.y as f32 / 384.; + + let r = 0.1 + trel / -10.; + for i in 0..20 { + let t = i as f32 / 20. * PI * 2.; + points.push((x + t.sin() * r, y + t.cos() * r)); + } + } + + for (x, y) in points { + out.write_all(&f32::to_le_bytes(x)).unwrap(); + out.write_all(&f32::to_le_bytes(y)).unwrap(); + } + } +} + +struct HitObject { + x: i32, + y: i32, + time: i32, +} + +fn parse_file(s: &str) -> Vec<HitObject> { + let mut obs = Vec::new(); + let b = s.split_once("[HitObjects]").unwrap().1; + for line in b.lines() { + if line.is_empty() { + continue; + } + let mut toks = line.split(","); + let x = toks.next().unwrap().parse().unwrap(); + let y = toks.next().unwrap().parse().unwrap(); + let time = toks.next().unwrap().parse().unwrap(); + obs.push(HitObject { x, y, time }) + } + obs +} |