tiled/
tiled.rs

1use graphics::{Image, Transformed};
2use graphics_buffer::*;
3
4fn main() {
5    // Load Matt Damon
6    let matt = RenderBuffer::decode_from_bytes(include_bytes!("matt.jpg")).unwrap();
7
8    // Initalize the buffer
9    let mut buffer = RenderBuffer::new(matt.width() * 2, matt.height() * 2);
10    buffer.clear([0.0, 0.0, 0.0, 1.0]);
11
12    // Tile the image with different colors
13    for (color, (x, y)) in &[
14        ([1.0, 0.2, 0.2, 1.0], (0.0, 0.0)), // red, top left
15        ([1.0, 1.0, 0.0, 1.0], (matt.width() as f64, 0.0)), // yellow, top right
16        ([0.0, 1.0, 0.0, 1.0], (0.0, matt.height() as f64)), // green, bottom left
17        (
18            [0.2, 0.2, 1.0, 1.0],                        // blue
19            (matt.width() as f64, matt.height() as f64), // bottom right
20        ),
21    ] {
22        Image::new_color(*color).draw(
23            &matt,
24            &Default::default(),
25            IDENTITY.trans(*x, *y),
26            &mut buffer,
27        );
28    }
29
30    // Save the image
31    buffer.save("tiled.png").unwrap();
32}