Function piston_window::rectangle

source ยท
pub fn rectangle<R, G>(
    color: [f32; 4],
    rect: R,
    transform: [[f64; 3]; 2],
    g: &mut G
)
where R: Into<[f64; 4]>, G: Graphics,
Expand description

Draws rectangle.

Examples found in repository?
examples/hello_piston.rs (lines 16-21)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() {
    let title = "Hello Piston! (press any key to enter inner loop)";
    let mut window: PistonWindow = WindowSettings::new(title, [640, 480])
        .exit_on_esc(true)
        .build()
        .unwrap_or_else(|e| panic!("Failed to build PistonWindow: {}", e));

    window.set_lazy(true);
    while let Some(e) = window.next() {
        window.draw_2d(&e, |c, g, _| {
            clear([0.5, 1.0, 0.5, 1.0], g);
            rectangle(
                [1.0, 0.0, 0.0, 1.0],
                [50.0, 50.0, 100.0, 100.0],
                c.transform,
                g,
            );
        });

        if e.press_args().is_some() {
            InnerApp {
                title: "Inner loop (press X to exit inner loop)",
                exit_button: Button::Keyboard(Key::X),
            }
            .run(&mut window);
            window.set_title(title.into());
        }
    }
}