Skip to content

Instantly share code, notes, and snippets.

@berak
Created September 11, 2012 09:58
Show Gist options
  • Select an option

  • Save berak/3697344 to your computer and use it in GitHub Desktop.

Select an option

Save berak/3697344 to your computer and use it in GitHub Desktop.
make checkers
#include <stdio.h>
#include <stdlib.h>
//
// checker 17 11 > ch17_11.pgm
//
int main(int argc, char **argv)
{
int w=argc>1?atoi(argv[1]):15;
int h=argc>2?atoi(argv[2]):9;
int b=argc>3?atoi(argv[3]):64; // must be pow2 !!
int ww = ( w + 2 ) * b;
int hh = ( h + 2 ) * b;
printf("P6\n%d %d\n255\n", ww, hh);
for ( int i = 0; i < hh; i++) {
for ( int j = 0; j < ww; j++) {
if ( i<=b || i>=hh-b || j<=b || j>=ww-b) {
putc(255,stdout);
putc(255,stdout);
putc(255,stdout);
continue;
}
unsigned char c = ((((i&b)==0)^((j&b)==0)))*255;
putc(c,stdout);
putc(c,stdout);
putc(c,stdout);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment