comforttiger

🐯 sorry, i bite

hi, i'm ~tiger~

i'm a 23 y/o pan tran voidgal
who loves faer cat and
is gay for @fruitbat

last.fm recent played


fruitbat
@fruitbat

today i got so upset about rust not being a shading language, i did the closest thing i could think of and tried generating animated gifs!

in the picture the one i generated is running on an led matrix, which looks a lot cooler than playing it on a regular screen but i'm allowed to cheat a lil!

the code for it is really cursed tho lmao


use gif::{Encoder, Frame, Repeat};
use std::borrow::Cow;
use std::fs::File;

fn main() {
let color_map = &[
0x00, 0x00, 0x00, //
0xF8, 0x90, 0x20, //
0x60, 0x28, 0x78, //
0x30, 0x00, 0x30, //
];

let frame_count = 64;
let (width, height) = (64, 32);
let mut image = File::create("target/beacon.gif").unwrap();
let mut encoder = Encoder::new(&mut image, width, height, color_map).unwrap();

encoder.set_repeat(Repeat::Infinite).unwrap();
(0..frame_count).for_each(|current_frame: u16| {
    let mut pixels = vec![];
    for y in 0..height {
        for x in 0..width {
            let height = (16.0 + (f32::sin((x + current_frame) as f32)))
                .round()
                .abs() as u16;
            if y == height {
                pixels.push(1);
            } else if (y == height + 6) || (y == height - 6) {
                pixels.push(2);
            } else if (y == height + 12) || (y == height - 12) {
                pixels.push(3);
            } else {
                pixels.push(0);
            }
        }
    }

    let mut frame = Frame::default();
    frame.width = width;
    frame.height = height;
    frame.buffer = Cow::Borrowed(&pixels);
    encoder.write_frame(&frame).unwrap();
});

}


You must log in to comment.

in reply to @fruitbat's post: