Skip to content

struct

ParticleOptions

pub struct ParticleOptions {
    pub count: u32,
    pub density: f32,
    pub colors: Vec<Color>,
    pub shapes: Vec<Sprite>,
    pub sides: u32,
    pub stroke: Color,
    pub stroke_width: f32,
    pub image: String,
    pub image_ratio: f32,
    pub opacity: f32,
    pub opacity_random: bool,
    pub opacity_speed: f32,
    pub opacity_min: f32,
    pub opacity_sync: bool,
    pub size: f32,
    pub size_random: bool,
    pub size_speed: f32,
    pub size_min: f32,
    pub size_sync: bool,
    pub links: bool,
    pub link_distance: f32,
    pub link_color: Color,
    pub link_opacity: f32,
    pub link_width: f32,
    pub moving: bool,
    pub speed: f32,
    pub direction: Direction,
    pub random_speed: bool,
    pub straight: bool,
    pub edge: Edge,
    pub collide: bool,
    pub attract: bool,
    pub attract_x: f32,
    pub attract_y: f32,
    pub detect: Detect,
    pub hover: Modes,
    pub click: Modes,
    pub grab_distance: f32,
    pub grab_opacity: f32,
    pub bubble_distance: f32,
    pub bubble_size: f32,
    pub bubble_opacity: f32,
    pub bubble_duration: f32,
    pub repulse_distance: f32,
    pub repulse_duration: f32,
    pub push: u32,
    pub remove: u32,
    pub seed: u64,
}

Everything about a particle background. Sizes and distances are CSS pixels; speeds are pixels per frame at 60 frames a second, halved (as in particles.js, whose options these follow).

Fields

count

pub count: u32

How many particles.

density

pub density: f32

With a value, count is per this many thousand square pixels and the number follows the area's size; 0 keeps count fixed.

colors

pub colors: Vec<Color>

Each particle picks one; empty means a random colour each.

shapes

pub shapes: Vec<Sprite>

Each particle picks one.

sides

pub sides: u32

For polygons and stars.

stroke

pub stroke: Color

The outline's colour.

stroke_width

pub stroke_width: f32

The outline's width (0: none).

image

pub image: String

An image to draw instead of shapes, by URL.

image_ratio

pub image_ratio: f32

The image's width over its height.

opacity

pub opacity: f32

Opacity, 0–1.

opacity_random

pub opacity_random: bool

Give each particle a random opacity up to opacity.

opacity_speed

pub opacity_speed: f32

Pulsing between opacity_min and opacity; 0 for none.

opacity_min

pub opacity_min: f32

The lowest opacity while pulsing.

opacity_sync

pub opacity_sync: bool

Every particle pulses together.

size

pub size: f32

Radius.

size_random

pub size_random: bool

Give each particle a random size up to size.

size_speed

pub size_speed: f32

Pulsing between size_min and size; 0 for none.

size_min

pub size_min: f32

The smallest size while pulsing.

size_sync

pub size_sync: bool

Every particle pulses together.

pub links: bool

Draw lines between nearby particles.

pub link_distance: f32

How near particles must be to be linked.

pub link_color: Color

The lines' colour.

pub link_opacity: f32

The lines' opacity at their shortest.

pub link_width: f32

The lines' width.

moving

pub moving: bool

Whether particles move.

speed

pub speed: f32

How fast they move.

direction

pub direction: Direction

Which way they drift.

random_speed

pub random_speed: bool

Vary the speed between particles.

straight

pub straight: bool

Every particle moves exactly in direction.

edge

pub edge: Edge

What happens at the edges.

collide

pub collide: bool

Particles bounce off each other.

attract

pub attract: bool

Linked particles pull together; smaller attract_x/attract_y pull harder.

attract_x

pub attract_x: f32

See attract.

attract_y

pub attract_y: f32

See attract.

detect

pub detect: Detect

Where the pointer is followed.

hover

pub hover: Modes

What hovering does.

click

pub click: Modes

What clicking does.

grab_distance

pub grab_distance: f32

How near the pointer grabs particles.

grab_opacity

pub grab_opacity: f32

The grab lines' opacity.

bubble_distance

pub bubble_distance: f32

How near the pointer makes particles bubble.

bubble_size

pub bubble_size: f32

A bubbling particle's size.

bubble_opacity

pub bubble_opacity: f32

A bubbling particle's opacity.

bubble_duration

pub bubble_duration: f32

Seconds a click's bubble takes to grow (and again to shrink).

repulse_distance

pub repulse_distance: f32

How near the pointer pushes particles away.

repulse_duration

pub repulse_duration: f32

Seconds a click's repulse lasts.

push

pub push: u32

How many particles a click adds.

remove

pub remove: u32

How many particles a click removes.

seed

pub seed: u64

Seeds the random numbers, so a background can be the same each time.

Methods

is_animated

pub fn is_animated(&self) -> bool

Whether the background changes from frame to frame.

count_for

pub fn count_for(&self, w: f32, h: f32) -> usize

How many particles fit a w × h area.

Trait implementations