Color

Struct Color 

Source
pub struct Color {
    pub red: u8,
    pub green: u8,
    pub blue: u8,
}
Expand description

Any color (or grayscale) value that this library can make PDF represent.

Fields§

§red: u8§green: u8§blue: u8

Implementations§

Source§

impl Color

Source

pub fn rgb(red: u8, green: u8, blue: u8) -> Self

Return a color from a RGB colorspace.

§Example
let white = Color::rgb(255, 255, 255);
let black = Color::rgb(0, 0, 0);
let red = Color::rgb(255, 0, 0);
let yellow = Color::rgb(255, 255, 0);
Examples found in repository?
examples/circles.rs (line 21)
13fn main() {
14    let (x, y) = (200.0, 200.0);
15    let r = 190.0;
16    let sides = 200;
17    let angles = (0..sides).map(|n| 2. * PI * n as f32 / sides as f32);
18
19    Pdf::new()
20        .add_page(400.0, 400.0)
21        .set_color(&Color::rgb(0, 0, 0))
22        .set_line_width(2.0)
23        .draw_circle(x, y, r)
24        .set_color(&Color::rgb(255, 230, 150))
25        .set_line_width(1.0)
26        .draw_line(angles.map(|phi| (x + r * phi.cos(), y + r * phi.sin())))
27        .write_to("circles.pdf")
28        .unwrap();
29}
Source

pub fn gray(gray: u8) -> Self

Return a grayscale color value.

§Example
let white = Color::gray(255);
let gray = Color::gray(128);
Examples found in repository?
examples/spectrum.rs (line 12)
4fn main() {
5    let x: Vec<f32> = (0..4096).map(|n| n as f32 / 4096. * 600.).collect();
6    let y: Vec<f32> = x.iter()
7        .map(|x| (-(x - 300.0).powi(2) / 1200.0).exp() * 600.0)
8        .collect();
9
10    Pdf::new()
11        .add_page(600.0, 600.0)
12        .set_color(&Color::gray(100))
13        .draw_line(x.into_iter().zip(y.into_iter()))
14        .write_to("spectrum.pdf")
15        .unwrap();
16}
More examples
Hide additional examples
examples/slideshow.rs (line 63)
58fn main() {
59    Slideshow::new(
60        1024.0,
61        769.0,
62        Font::Helvetica,
63        Color::gray(0),
64        Color::gray(255),
65    ).add_title_slide("Lessons from LATHER")
66        .add_text_slide("The Activity Problem\nOR\nRemove the spots")
67        .add_text_slide(
68            "1. Find/make a good model\n2. Run it. A lot.\n3. Listen at group meetings",
69        )
70        .add_text_slide("Easy to use\nWe're going to write a lot of scripts")
71        .add_text_slide("SOAP: 2.4 s\nLATHER: 0.006 s")
72        .add_text_slide("All I Really Need to Know I Learned in\nKindergarten")
73        .add_text_slide(
74            "All I Really Need to Know I Learned in\nMathematical Physics",
75        )
76        .write_to("lessons_from_lather.pdf")
77        .expect("Couldn't save slideshow");
78}
examples/mandala.rs (line 21)
8fn main() {
9    let mut args = env::args().skip(1);
10    let n: usize = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
11
12    let angle = 2.0 * PI / n as f32;
13    let r = 99.0;
14    let d = 141.4;
15    let rr = 36.0;
16
17    let mut document = Pdf::new();
18    document
19        .add_page(600.0, 600.0)
20        .transform(Matrix::translate(300.0, 300.0))
21        .set_color(&Color::gray(0));
22
23    for _ in 0..n {
24        document
25            .draw_line(vec![(0.0, 33.5), (0.0, 250.0)].into_iter())
26            .draw_circle(0.0, r, r * 1.25 * angle)
27            .draw_circle(0.0, d + rr, rr)
28            .transform(Matrix::rotate(angle));
29    }
30    document.transform(Matrix::rotate(angle / 2.0));
31    for _ in 0..n {
32        let mut r0 = 58.66;
33        let mut r = 0.7705 * r0 * angle;
34        for _ in 0..(n + 1) / 3 {
35            document.draw_circle(0., r0, r);
36            let r2 = 1.058 * r;
37            r0 += r + r2;
38            r = r2;
39        }
40        document.transform(Matrix::rotate(angle));
41    }
42
43    document.write_to("mandala.pdf").unwrap();
44}

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

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.