pub struct ConfettiSystem { /* private fields */ }Expand description
An owned collection of confetti particles that animate together.
Create with ConfettiSystem::burst, drive per frame with
ConfettiSystem::tick + ConfettiSystem::paint. The system owns all
particle state; there is no shared or global mutable state.
Implementations§
Source§impl ConfettiSystem
impl ConfettiSystem
Sourcepub fn burst(bounds: Rect, count: usize, palette: &[Color], seed: u64) -> Self
pub fn burst(bounds: Rect, count: usize, palette: &[Color], seed: u64) -> Self
Spawn a burst of count flakes across the top region of bounds.
Flakes start near the top edge with a slight upward/outward velocity
spread, then fall under gravity while fluttering horizontally. Colors are
drawn from palette (cycled deterministically); an empty palette yields
white flakes. seed fully determines the burst — the same seed produces
the same particle stream on every platform.
Coordinates are Y-up: the “top region” is the high-Y band of bounds.
Sourcepub fn particle_count(&self) -> usize
pub fn particle_count(&self) -> usize
Number of live particles remaining.
Sourcepub fn tick(&mut self, dt_seconds: f64) -> bool
pub fn tick(&mut self, dt_seconds: f64) -> bool
Advance the simulation by dt_seconds and return whether the burst is
still alive (any particle remaining).
Expired particles are removed. A non-finite or negative dt is treated
as 0.0, so a hostile or degenerate frame delta can never introduce NaN
into particle positions. While particles remain, this calls
request_draw so the host keeps drawing frames until the burst
finishes on its own.
Sourcepub fn paint(&self, ctx: &mut dyn DrawCtx)
pub fn paint(&self, ctx: &mut dyn DrawCtx)
Paint every live particle as a rotated, alpha-faded filled rectangle.
Drawn in the current coordinate space (Y-up); callers position the burst
by setting up ctx’s transform before calling, or by passing bounds in
the same space they paint in. A few hundred particles paint comfortably
with the standard DrawCtx fill path.
Auto Trait Implementations§
impl Freeze for ConfettiSystem
impl RefUnwindSafe for ConfettiSystem
impl Send for ConfettiSystem
impl Sync for ConfettiSystem
impl Unpin for ConfettiSystem
impl UnsafeUnpin for ConfettiSystem
impl UnwindSafe for ConfettiSystem
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
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