Skip to content

Instantly share code, notes, and snippets.

@xyproto
Forked from kusma/bayer-gen.c
Created August 5, 2010 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyproto/510027 to your computer and use it in GitHub Desktop.
Save xyproto/510027 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
const int seed[2][2] = {{0, 2}, {3, 1}};
int main(int argc, char *argv[])
{
unsigned x, y, m = 3;
if (argc == 2)
m = atoi(argv[1]);
if (argc > 2 || m < 1 || m > sizeof(int) * 4)
fprintf(stderr, "usage: %s [mag]\n", argv[0]), exit(-1);
for (y = 0; y < 1 << m; ++y, putchar('\n'))
for (x = 0; x < 1 << m; ++x) {
unsigned i, v = 0;
for (i = 0; i < m; ++i)
v = 4 * v + seed[(x >> i) % 2][(y >> i) % 2];
printf("%u ", v);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment