35 lines
682 B
C
35 lines
682 B
C
/* xor texture generator */
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
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;
|
|
}
|