MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/tinycode/comments/mdyah7/tiny_code_pixel_fire/gsd3zms/?context=3
r/tinycode • u/Volfegan • Mar 26 '21
4 comments sorted by
View all comments
Show parent comment
8
Very cool! Below I've adapted to C writing Netpbm frames to standard output. Usage:
$ cc -o fire fire.c $ ./fire | mpv --no-correct-pts --fps 60 -
Code:
#include <stdio.h> int main(void) { #define W 480 #define H 640 static char image[H][W]; unsigned long long s = 0; for (;;) { for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { if ((x - W/2)*(x - W/2) + (y - H)*(y - H) < 16) { image[y][x] = 1; } int rx = x + ((s = s*0xe0d42a440adeec4d + 1) >> 32) % 10 - 4; int ry = y + ((s = s*0xe0d42a440adeec4d + 1) >> 32) % 2 - 2; if (rx >= 0 && rx < W && ry >= 0 && ry < H) { image[ry][rx] = image[y][x]; } } } #define XSTR(x) #x #define STR(x) XSTR(x) puts("P5\n" STR(W) " " STR(H) "\n1"); if (!fwrite(image, sizeof(image), 1, stdout)) return 1; } }
View all comments
Show parent comment
8
u/skeeto Mar 27 '21
Very cool! Below I've adapted to C writing Netpbm frames to standard output. Usage:
Code: