[][src]Struct rustbatch::render::particle::system::ParticleSystem

pub struct ParticleSystem<P: Particle, G: Generator> { /* fields omitted */ }

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

impl<P: Particle, G: Generator> ParticleSystem<P, G>[src]

pub fn customized(
    batch: Batch,
    config: ParticleConfig,
    shape: P,
    generator: G
) -> Self
[src]

this is a core constructor. You will not get more customization then this.

pub fn spawn(&mut self, count: usize, pos: Vect, dir: Vect)[src]

spawns particles on given position in given direction

pub fn update(&mut self, delta: f32)[src]

call it every frame

pub fn draw<T: Target>(&self, target: &mut T)[src]

draw draws particles to target

Auto Trait Implementations

impl<P, G> RefUnwindSafe for ParticleSystem<P, G> where
    G: RefUnwindSafe,
    P: 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> where
    G: Unpin,
    P: Unpin

impl<P, G> UnwindSafe for ParticleSystem<P, G> where
    G: UnwindSafe,
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,