From f65ea2ae5dad44d8f1f950a54570024b63a08f76 Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Sun, 2 Feb 2025 19:14:05 -0300 Subject: [PATCH] add xortex.c --- audiovisual/xortex.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 audiovisual/xortex.c diff --git a/audiovisual/xortex.c b/audiovisual/xortex.c new file mode 100644 index 0000000..844d3fa --- /dev/null +++ b/audiovisual/xortex.c @@ -0,0 +1,35 @@ +/* xor texture generator */ +#include +#include + +size_t +strlen(const char *); + +int +main(int argc, char **argv) +{ + const char palette_def[] = "WO0KXkxocl;:*,'."; + const char *palette = palette_def; + + int w = 48, h = 48; + if (argc > 2) { + w = atoi(argv[1]); + h = atoi(argv[2]); + } + if (argc > 3) + palette = argv[3]; + int palette_len = strlen(palette); + if (palette_len == 0 || palette_len & (palette_len - 1)) { + fputs("palette length must be a power of two\n", stderr); + return 1; + } + + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + uint8_t c = (x>>1) ^ (y>>1); + putchar(palette[c & (palette_len-1)]); + } + putchar('\n'); + } + return 0; +}