Color

Struct Color 

Source
pub struct Color { /* private fields */ }
Expand description

A color with red, green, and blue components.

Implementations§

Source§

impl Color

Source

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
Hide additional 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}
Source

pub fn red(&self) -> i32

Returns the red component.

Source

pub fn green(&self) -> i32

Returns the green component.

Source

pub fn blue(&self) -> i32

Returns the blue component.

Source

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§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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 UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.