create_image/
create-image.rs

1use pixtra::canvas::Canvas;
2use pixtra::pixels::Pixel;
3
4fn main() {
5    let color = Pixel {
6        r: 255,
7        g: 255,
8        b: 0,
9        a: 255,
10    };
11
12    // Creates new blank canvas. Blank is white.
13    let mut canvas = Canvas::new(10, 10);
14
15    canvas.set_pixel_mut(5, 5, &color);
16
17    let pixel = canvas.get_pixel(5, 5);
18
19    assert_eq!(color, pixel);
20    println!("We found color {} and we expected color {}", pixel, color);
21
22    // We can do the same without the _mut modifier
23    let color = Pixel {
24        r: 255,
25        g: 255,
26        b: 0,
27        a: 255,
28    };
29
30    // Creates new blank canvas. Blank is white.
31    let canvas = Canvas::new(10, 10);
32
33    // Here is the difference.
34    // We discard the old canvas and use the new one which contains the new pixel
35    let canvas = canvas.set_pixel(5, 5, &color);
36
37    let pixel = canvas.get_pixel(5, 5);
38
39    assert_eq!(color, pixel);
40    println!("We found color {} and we expected color {}", pixel, color);
41}