circles/
circles.rs

1//! Example program drawing circles on a page.
2extern crate pdfpdf;
3
4use pdfpdf::{Color, Pdf};
5use std::f32::consts::PI;
6
7/// Create a `circles.pdf` file, with a single page containg a circle
8/// stroked in black, overwritten with a circle in a finer yellow
9/// stroke.
10/// The black circle is drawn using the `Canvas.circle` method,
11/// which approximates a circle with four bezier curves.
12/// The yellow circle is drawn as a 200-sided polygon.
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}