Created
September 11, 2012 09:58
-
-
Save berak/3697344 to your computer and use it in GitHub Desktop.
make checkers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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