Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [2018-07-13] Challenge #365 [Hard] Tessellations and Tilings
- /r/dailyprogrammer https://redd.it/8ylltu
- *grumble*grumble* *mutter...*
- i hope you like this, view output at: https://imgur.com/a/pKyjatF
- it doesn't seem so bad now... :/
- usage: $ for i in bullshit*.txt; do
- cat $i | ./bullshit | ffmpeg -i /dev/stdin $(basename $i .txt).png
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define FORIJ(N) for(int j = 0; j < (N); j++) \
- for(int i = 0; i < (N); i++)
- #define ROT90(N, BEFORE, AFTER, TMP) do { \
- FORIJ(N) TMP[i][(N)-j-1] = BEFORE[j][i]; \
- FORIJ(N) AFTER[j][i] = TMP[j][i]; \
- } while(0)
- extern unsigned char font[]; /* forward declaration, long array */
- typedef struct { int ch; int rot; char x[8][8]; } glyph_t;
- glyph_t mk_glyph(int ch, int rot) {
- glyph_t ret;
- ch %= 256;
- if(rot < 0) rot = rot + (-4)*((rot-3)/4);
- rot %= 4;
- FORIJ(8) {
- int byte = font[8*ch + j];
- int mask = (0x80 >> i);
- int x = (byte & mask) ? 'x' : '.';
- ret.x[j][i] = x;
- }
- char scratch[8][8];
- while(rot--) { ROT90(8, ret.x, ret.x, scratch); }
- ret.ch = ch; ret.rot = rot;
- return ret;
- }
- void print_glyph(glyph_t g) {
- for(int j = 0; j < 8; j++) {
- for(int i = 0; i < 8; i++) putc(g.x[j][i], stdout);
- putc('\n', stdout);
- }
- return;
- }
- #define MAX_N 12
- #define MAX_PX (8*N)
- int N;
- int PX;
- int TURN;
- glyph_t grid[2*MAX_N][2*MAX_N];
- glyph_t after[MAX_N][MAX_N];
- glyph_t scratch[MAX_N][MAX_N];
- int main(int argc, char *argv[]) {
- int tmp, c;
- tmp = scanf("%d", &TURN);
- if(tmp <= 0 || (TURN % 90)) { fprintf(stderr, "bad TURN\n"); exit(1); }
- if(TURN < 0) { TURN = TURN + (-90)*((TURN-90)/90); }
- TURN = (TURN / 90) % 4;
- tmp = scanf("%d", &N);
- if(tmp <= 0 || N < 1 || N >= MAX_N) { fprintf(stderr, "bad N\n"); exit(1); }
- for(int i = 0; i < N*N; i++) {
- do { c = getc(stdin); } while(!isprint(c));
- int row = i / N;
- int col = i % N;
- after[row][col] = mk_glyph(c, 0);
- }
- FORIJ(N) { grid[0+j][0+i] = mk_glyph(after[j][i].ch, 0*TURN); }
- for(int i = 0; i < TURN; i++) ROT90(N, after, after, scratch);
- FORIJ(N) { grid[0+j][N+i] = mk_glyph(after[j][i].ch, 1*TURN); }
- for(int i = 0; i < TURN; i++) ROT90(N, after, after, scratch);
- FORIJ(N) { grid[N+j][N+i] = mk_glyph(after[j][i].ch, 2*TURN); }
- for(int i = 0; i < TURN; i++) ROT90(N, after, after, scratch);
- FORIJ(N) { grid[N+j][0+i] = mk_glyph(after[j][i].ch, 3*TURN); }
- PX = 8*2*N;
- printf("P1\n%d %d\n1", PX, PX);
- int width = 0;
- FORIJ(PX) {
- if(width == 0) printf("\n");
- width = (width + 2) % 64;
- glyph_t g = grid[j / 8][i / 8];
- int x = g.x[j % 8][i % 8];
- if(x == 'x') printf(" 1");
- else printf(" 0");
- }
- printf("\n");
- return 0;
- }
- /* http://web.mit.edu/freebsd/head/share/syscons/fonts/cp437-8x8.fnt after uudecode */
Advertisement
Add Comment
Please, Sign In to add comment