The Plasma library written in rust. Api reference.
Cargo.toml
:
[dependencies]
rand = "0.8"
[dependencies.plasma]
git = "https://github.com/royaltm/rust-plasma.git"
main.rs
:
use plasma::*;
Then somwehere in the code:
let min_steps = 80.0f32;
let max_steps = 200.0f32;
let plasma_width = 200u32;
let plasma_height = 200u32;
let mut rng = rand::thread_rng();
let cfg = PhaseAmpCfg::new(min_steps, max_steps);
let mut plasma = Plasma::new(plasma_width, plasma_height, cfg, &mut rng);
loop {
let buffer_rgb24: &mut [u8] = get_image_buffer_from_somwhere();
let pitch: usize = get_how_many_bytes_per_line();
plasma.render::<PixelBufRGB24, PlasmaICP, PlasmaMixer>(buffer_rgb24, pitch, None);
display_buffer_on_screen();
plasma.update(&mut rng);
}
std
(default) - compile withstd
library.use-simd
- specialized implementation with SIMD instructions. Available only forx86
,x86_64
oraarch64
architectures, requires nightly rustc features. A significant CPU optimization boost can be achieved if compiled with advancedtarget-cpu
feature flags. Enablesstd
.micromath
- (alternative tolibm
) provides math routines forno_std
.libm
- (alternative tomicromath
) provides math routines forno_std
.
SIMD accelerated:
RUSTFLAGS='-C target-cpu=+avx2' cargo build --release --features=use-simd
RUSTFLAGS='-C target-cpu=native' cargo build --release --features=use-simd
cargo +nightly bench --bench render --features=rand/std -- --nocapture
RUSTFLAGS='-C target-cpu=native' cargo +nightly bench --bench render --features=rand/std,use-simd -- --nocapture
In no_std
mode plasma
library still depends on the alloc
crate and in addition requires one of the two math libraries, which must be enabled by the depending crate:
Cargo.toml
:
[dependencies.plasma]
version = "0.2"
git = "https://github.com/royaltm/rust-plasma.git"
default-features = false
features = ["libm"] # or "micromath"