Skip to main content

conv/
conv.rs

1use rainbow::SrgbRgba;
2
3fn main() {
4    // You can create colors using floats...
5    let color = dbg!(SrgbRgba::from_f32(0.0, 1.0, 0.5, 1.0));
6    // or using integers. These colors are approximately identical, being only
7    // slightly different due to `u8` affording less precision.
8    dbg!(SrgbRgba::from_u8(0x00, 0xFF, 0x80, 0xFF));
9    // Naturally, you can also convert to arrays of either type:
10    dbg!(color.into_f32_array());
11    dbg!(color.into_u8_array());
12    // If you want to convert to linear, that's easy too:
13    dbg!(color.to_linear());
14    // `LinRgba` has all of the same conversion methods as `SrgbRgba`, save for
15    // providing `to_srgb` instead of `to_linear`.
16}