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: u8Implementations§
Source§impl Color
impl Color
Sourcepub fn rgb(red: u8, green: u8, blue: u8) -> Self
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}Sourcepub fn gray(gray: u8) -> Self
pub fn gray(gray: u8) -> Self
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
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§
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