1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}
|