[−][src]Trait cichlid::prelude::ColorSliceMut
Optimized methods for iterating over arrays and slices of ColorRGB
s.
Usage
Normally, to scale an array by a fixed amount, something like is done:
use cichlid::ColorRGB; let mut colors = [ColorRGB::Pink; 50]; colors.iter_mut().for_each(|c| c.fade_to_black_by(200));
But, when operating on arrays, it's often faster to operate on multiple values at once
using custom SIMD functions. ColorSliceMut::fade_to_black()
implements this internally,
resulting in dimming that is twice as fast as the above method.
use cichlid::{prelude::*, ColorRGB}; let mut colors = [ColorRGB::Pink; 50]; colors.fade_to_black(200); // Much faster!
Examples
use cichlid::{prelude::*, ColorRGB}; let mut colors = [ColorRGB::Purple; 50]; colors.fade_to_black(50); let color_slice = &mut colors[0..40]; color_slice.blur(50); color_slice.blend(ColorRGB::Gold, 120);
Required methods
fn blur(self, blur_amount: u8)
Blurs colors by blur_amount
.
A lower blur_amount
means a less extreme blur. For example, a blur_amount
of 64
is a moderate blur, while past 171 the blur is somewhat flickery.
This method does not retain brightness. Blurring will slowly fade all the colors to black.
fn fade_to_black(self, fade_by: u8)
Fades all colors to black by a fraction.
The fade_by
parameter is interpreted as a fraction with a denominator of 255,
of which itself is the numerator. A higher fade_by
means the colors a larger fade,
while a lower face_by
results in less dimmed colors.
fn blend(self, other: ColorRGB, amount_of_other: u8)
Applies ColorRGB::blend()
to the entire slice.