pub struct EdgeSnake {
pub x: u16,
pub y: u16,
last_update: Instant,
frame_duration: Duration,
}Expand description
Manages a snake animation that moves along the terminal boundaries. The snake follows the edges of the given area in a clockwise direction.
Fields§
§x: u16Current horizontal position of the head.
y: u16Current vertical position of the head.
last_update: InstantLast update timestamp for frame rate control.
frame_duration: DurationTarget duration between animation frames (speed).
Implementations§
Source§impl EdgeSnake
impl EdgeSnake
Sourcepub fn update(&mut self, area: &Rect)
pub fn update(&mut self, area: &Rect)
Updates the snake’s position along the edges.
The movement is constrained by a fixed frame rate.
pub fn render(&self, frame: &mut Frame<'_>, area: &Rect)
Sourcefn get_limits(width: u16, height: u16) -> (u16, u16)
fn get_limits(width: u16, height: u16) -> (u16, u16)
Computes terminal-specific boundaries for the snake.
Returns (max_x, max_y).
Sourcepub fn step_along_edge(
x: u16,
y: u16,
max_x: u16,
max_y: u16,
delta: i32,
) -> (u16, u16)
pub fn step_along_edge( x: u16, y: u16, max_x: u16, max_y: u16, delta: i32, ) -> (u16, u16)
Having a little fun with mathematics, as simple if condition can do the tricks also
Unified helper that steps a given number of cells along the perimeter.
A delta of 1 moves clockwise; -1 moves counter-clockwise.
Sourcefn is_vertical(x: u16, y: u16, max_x: u16, max_y: u16) -> bool
fn is_vertical(x: u16, y: u16, max_x: u16, max_y: u16) -> bool
Checks if the segment at (x, y) is on a vertical edge.
Sourcepub fn get_positions(&self, width: u16, height: u16) -> Vec<(u16, u16)>
pub fn get_positions(&self, width: u16, height: u16) -> Vec<(u16, u16)>
Returns the coordinates for all snake segments, starting from the head and going TOTAL_SEGMENTS time back
Calculate each position as if size was 1, and compute an offset to do that the good amount of time (different between width and height)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EdgeSnake
impl RefUnwindSafe for EdgeSnake
impl Send for EdgeSnake
impl Sync for EdgeSnake
impl Unpin for EdgeSnake
impl UnsafeUnpin for EdgeSnake
impl UnwindSafe for EdgeSnake
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more