add xortex.c
This commit is contained in:
parent
d1f006dd54
commit
f65ea2ae5d
1 changed files with 35 additions and 0 deletions
35
audiovisual/xortex.c
Normal file
35
audiovisual/xortex.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* 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;
|
||||
}
|
Loading…
Add table
Reference in a new issue