pub struct ParticleSystem<P: Particle, G: Generator> { /* private fields */ }
Expand description
ParticleSystem is particle system. You can use custom shapes and position generator. other way to customize particles it though config.
§example
use rustbatch::{Window, Batch, Vect, FPS};
use rustbatch::render::particle::system::{ ParticleSystem, Initial, RandomizedProperty, Dynamic, Property};
use rustbatch::render::particle::system;
use rustbatch::math::rgba::{Graph, GraphPoint};
use std::f32::consts::PI;
use rustbatch::math::curve::Curve;
use rustbatch::render::particle::shapes::{SymmetricShape, Triangle};
use rustbatch::vect;
let (mut window, mut pump, _f, _g, _r) = Window::new(|sys| sys.window("segmentation", 400, 400).opengl().build().unwrap());
let mut sys = system::no_texture(system::ParticleConfig {
rotation_relative_to_spawn_direction: true,
inverted: false,
gravity: Vect::DOWN * 2.0,
color: Graph::new(vec![GraphPoint::new(0.0, [0.0, 0.0, 1.0, 0.5]), GraphPoint::new(0.5, [1.0, 1.0, 0.0, 1.0]), GraphPoint::new(1.0, [0.0, 1.0, 0.0, 0.0])]),
spread: PI,
friction: 2.0,
origin_attraction: 10.0,
initial: Initial {
velocity: RandomizedProperty::new(300.0, 150.0),
rotation: RandomizedProperty::no_random(0.0),
twerk: RandomizedProperty::no_random(10.0),
live_time: RandomizedProperty::new(1.0, 0.5),
},
dynamic: Dynamic {
acceleration: Property { curve: Curve::NONE, value: 0.0 },
twerk_acceleration: Property { curve: Curve::NONE, value: 0.0 },
scale: Property { curve: Curve::NONE, value: 20.0 }
}
}, Triangle::new(&[Vect::unit(0.0), Vect::unit(2.0 * PI/3.0), Vect::unit(4.0 * PI/3.0)]));
let mut fps = FPS::new(1f32);
'main: loop {
for event in pump.poll_iter() {
match event {
/// break loop if X button on window is pressed
sdl2::event::Event::Quit { .. } => break 'main,
_ => {}
}
}
let delta = fps.increase(0f32);
window.clear();
sys.update(delta);
sys.spawn(10, vect!(0, 0), vect!(1, 0));
sys.draw(&mut window.canvas);
window.update();
}
Implementations§
Source§impl<P: Particle, G: Generator> ParticleSystem<P, G>
impl<P: Particle, G: Generator> ParticleSystem<P, G>
Sourcepub fn customized(
batch: Batch,
config: ParticleConfig,
shape: P,
generator: G,
) -> Self
pub fn customized( batch: Batch, config: ParticleConfig, shape: P, generator: G, ) -> Self
this is a core constructor. You will not get more customization then this.
Auto Trait Implementations§
impl<P, G> Freeze for ParticleSystem<P, G>
impl<P, G> RefUnwindSafe for ParticleSystem<P, G>where
P: RefUnwindSafe,
G: RefUnwindSafe,
impl<P, G> !Send for ParticleSystem<P, G>
impl<P, G> !Sync for ParticleSystem<P, G>
impl<P, G> Unpin for ParticleSystem<P, G>
impl<P, G> UnwindSafe for ParticleSystem<P, G>where
P: UnwindSafe,
G: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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