pub fn create_anim<T: AsRef<[u32]>>(
width: u32,
height: u32,
data: &[T],
filepath: &str,
) -> Result<(), Error>Expand description
Writes an animated png image from the given 2d u32 slice.
Examples found in repository?
examples/rainbowsquare.rs (line 59)
1fn main() {
2 let mut colour: u32 = 0xFF0000FF;
3 enum Colourd {
4 Redplusgreen,
5 Greenminusred,
6 Greenplusblue,
7 Blueminusgreen,
8 Blueplusred,
9 Redminusblue,
10 }
11 let mut cd = Colourd::Redplusgreen;
12 let mut data: Vec<Vec<u32>> = Vec::new();
13 loop {
14 match cd {
15 Colourd::Redplusgreen => {
16 data.push(Vec::from([colour; 256]));
17 colour = colour.saturating_add(0x050000);
18 if colour >> 16 & 0xFF == 0xFF {
19 cd = Colourd::Greenminusred;
20 }
21 }
22 Colourd::Greenminusred => {
23 data.push(Vec::from([colour; 256]));
24 colour = colour.saturating_sub(0x05000000);
25 if colour >> 24 & 0xFF == 0x0 {
26 cd = Colourd::Greenplusblue;
27 }
28 }
29 Colourd::Greenplusblue => {
30 data.push(Vec::from([colour; 256]));
31 colour = colour.saturating_add(0x0500);
32 if colour >> 8 & 0xFF == 0xFF {
33 cd = Colourd::Blueminusgreen;
34 }
35 }
36 Colourd::Blueminusgreen => {
37 data.push(Vec::from([colour; 256]));
38 colour = colour.saturating_sub(0x050000);
39 if colour >> 16 & 0xFF == 0x0 {
40 cd = Colourd::Blueplusred;
41 }
42 }
43 Colourd::Blueplusred => {
44 data.push(Vec::from([colour; 256]));
45 colour = colour.saturating_add(0x05000000);
46 if colour >> 24 & 0xFF == 0xFF {
47 cd = Colourd::Redminusblue;
48 }
49 }
50 Colourd::Redminusblue => {
51 if colour >> 8 & 0xFF == 0x0 {
52 break;
53 }
54 data.push(Vec::from([colour; 256]));
55 colour = colour.saturating_sub(0x0500);
56 }
57 }
58 }
59 match pingus::create_anim(16, 16, &data, "rainbowsquare.png") {
60 Ok(_) => {
61 println!("\x1B[32mRainbowsquare created successfully.\x1B[0m");
62 }
63 Err(e) => {
64 println!("\x1B[33mFailed to create rainbowsquare: \x1B[31m{e}\x1B[0m");
65 }
66 }
67}