pub struct Color(/* private fields */);Expand description
A color and opacity
Implementations§
Source§impl Color
impl Color
Sourcepub fn new(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self
Define a new color
Examples found in repository?
examples/gradation.rs (line 25)
8fn main() {
9 let background_color = "#ddd".try_into().unwrap();
10 let mut canvas_builder = Canvas::builder()
11 .size(2560.0, 1440.0)
12 .background_color(background_color)
13 .points(
14 Lattice::rectangular_builder()
15 .grid_size(7, 5)
16 .len_a(300.0)
17 .len_b(200.0)
18 .build(),
19 );
20
21 canvas_builder.add_shape(
22 Polygon::builder()
23 .sides_fn(|Index { u, .. }| *u as u8 + 3)
24 .size_fn(|Index { v, .. }| *v as f64 * 35.0 + 80.0)
25 .color_fn(|Index { u, v }| Color::new((*u + 1) as u8 * 25, 0, (*v + 1) as u8 * 25, 255))
26 .build(),
27 );
28
29 let canvas = canvas_builder.build();
30 let document = canvas.render(|_| true);
31 svg::save("examples/gradation.svg", &document).unwrap();
32}Sourcepub fn from_hex(hex: &str) -> Result<Self, ParseHexColorError>
pub fn from_hex(hex: &str) -> Result<Self, ParseHexColorError>
Define a new color from a hex string
Trait Implementations§
impl Copy for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnsafeUnpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more