This commit is contained in:
2024-10-01 22:20:23 -06:00
parent 54afb64ae8
commit 1b09b4e235

View File

@@ -3,20 +3,20 @@ use std::io::stdin;
use macroquad::prelude::*;
const DOT_RADIUS: f32 = 1.0;
const DOT_RADIUS: f32 = 2.0;
const TAIL_LEN: usize = 250;
#[derive(Clone,Copy)]
struct Dot {
x: f32,
y: f32,
}
impl Dot {
fn new(x: f32, y: f32) -> Self {
Self {x,y}
}
fn draw(&self) {
draw_circle(self.x, self.y,DOT_RADIUS, GREEN);
fn draw(&self, color: Color) {
draw_circle(self.x, self.y,DOT_RADIUS, color);
}
}
@@ -48,36 +48,35 @@ impl DebugWindow {
}
}
enum Axis {
One,
Two
}
struct Tail {
points: [Dot; 500],
points: [Dot; TAIL_LEN],
head: usize,
axis: Axis,
/// What the tail treats as 0
x_offset: f32,
/// What the tail treats as 0
y_offset: f32,
/// How fast X scrolls when using a since axis tail
px_per_s: f32,
}
impl Tail {
fn new(axis: Axis) -> Self {
let (x_offset, y_offset) = match axis {
Axis::One => (0., screen_height() /2.),
Axis::Two => (screen_width() /2., screen_height() /2.),
};
Self {
// start all the dots off screen
points: [Dot::new(-1.,-1.); 500],
points: [Dot::new(-1.,-1.); TAIL_LEN],
head: 0,
axis,
x_offset,
y_offset,
px_per_s: 500.,
px_per_s: 1000.,
}
}
fn place_next(&mut self, delta_time: f32, x_displace: f32, y_displace: f32) {
@@ -107,8 +106,19 @@ impl Tail {
self.points[self.head] = dot;
}
fn draw(&self) {
// TODO fadding alpha?
self.points.iter().for_each(|d| d.draw());
self.points.into_iter().enumerate().for_each(|(index, dot) |{
let virtual_index = if index > self.head {
index-self.head
} else {
index + (self.points.len() - self.head)
};
let faded = virtual_index as f32 / self.points.len() as f32;
let faded_inverse = 1. - faded;
// dots fade
dot.draw(Color { r: faded_inverse, g: faded, b: 0.2, a: faded+0.1});
});
}
fn dots(&self) -> usize {
self.points.len()
@@ -120,7 +130,7 @@ async fn main() {
// Dot params
let mut y_displacement = 0.;
let mut x_displacement = 0.;
let mut tail = Tail::new(Axis::Two);
let mut tail = Tail::new(Axis::One);
// Selection box
let mut inital_x_pos = 0.;
@@ -128,7 +138,6 @@ async fn main() {
// Tooling
let mut show_debug = true;
let mut px_per_s: f32 = 1000.;
let stdin = stdin();
let handle= stdin.lock();
@@ -164,12 +173,6 @@ async fn main() {
if is_key_pressed(KeyCode::F3) {
show_debug = !show_debug;
}
if is_key_pressed(KeyCode::Up) {
px_per_s += 5.;
}
if is_key_pressed(KeyCode::Down) {
px_per_s -= 5.;
}
// selection box
if is_mouse_button_pressed(MouseButton::Left) {
(inital_x_pos, inital_y_pos) = mouse_position();
@@ -188,7 +191,6 @@ async fn main() {
debug.add_line(format!("FPS {}, Latency {:.2}ms", get_fps(), delta_time * 1000.0));
debug.add_line(format!("Dots {}", tail.dots()));
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
debug.add_line(format!("px/s {}", px_per_s));
debug.draw();
}