pub struct Color { /* private fields */ }Expand description
A color with red, green, and blue components.
Implementations§
Source§impl Color
impl Color
Sourcepub fn new(red: i32, green: i32, blue: i32) -> Result<Color>
pub fn new(red: i32, green: i32, blue: i32) -> Result<Color>
Returns a new color, validating each component is in the range [0, 255].
Examples found in repository?
examples/examples.rs (line 11)
10pub fn main() -> Result<()> {
11 let blue = Color::new(56, 103, 165)?;
12 let yellow = Color::new(242, 205, 21)?;
13 let gold = Color::new(242, 174, 45)?;
14 let orange = Color::new(216, 140, 73)?;
15 let burnt = Color::new(191, 86, 47)?;
16
17 Ex3636::render(blue, yellow, gold, orange, burnt)?;
18 Ex33434::render(blue, yellow, gold, orange, burnt)?;
19 Ex33336::render(blue, yellow, gold, orange, burnt)?;
20 Ex333333::render(blue, yellow, gold, orange, burnt)?;
21
22 Ok(())
23}More examples
examples/intro.rs (line 7)
3pub fn main() -> Result<()> {
4 let width = 1024;
5 let height = 1024;
6 let scale = 128.0;
7 let stroke = Color::new(242, 60, 60)?;
8 let fill_hexagon = Color::new(242, 194, 106)?;
9 let fill_square = Color::new(23, 216, 146)?;
10 let fill_triangle = Color::new(242, 209, 48)?;
11 let background = Color::new(242, 242, 242)?;
12 let margin = 0.1;
13 let show_labels = false;
14 let line_width = 0.1;
15
16 // create an empty model
17 let mut model = Model::new(width, height, scale);
18
19 // add a hexagon
20 model.add(Shape::new(6, fill_hexagon, stroke)?);
21
22 // attach a square to each side of the hexagon
23 let squares = model.add_multi(0..1, 0..6, Shape::new(4, fill_square, stroke)?)?;
24
25 // attach a triangle between the squares
26 let _ = model.add_multi(squares.clone(), 1..2, Shape::new(3, fill_triangle, stroke)?)?;
27
28 // attach a hexagon to the outer edge of each square
29 let hexagons = model.add_multi(squares.clone(), 2..3, Shape::new(6, fill_hexagon, stroke)?)?;
30
31 // fill the surface with the pattern
32 model.repeat(hexagons)?;
33
34 // render the tiling
35 let render = model.render(background, margin, line_width, show_labels)?;
36 render.write_to_png("intro.png")?;
37
38 // render the dual tiling
39 let render_dual = model.render_dual(background, fill_hexagon, stroke, margin, line_width)?;
40 render_dual.write_to_png("intro-dual.png")?;
41
42 Ok(())
43}Sourcepub fn rgb_unit_int(&self) -> (f64, f64, f64)
pub fn rgb_unit_int(&self) -> (f64, f64, f64)
Returns the red, green, and blue comonents as a tuple where each component has been translated into the unit interval (0 to 1 inclusive).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin 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