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