diff options
author | kartofen <mladenovnasko0@gmail.com> | 2022-08-11 16:41:00 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2022-08-11 16:41:00 +0300 |
commit | 57315da56fa3b036f8e3e2d32a5f90a11ae7c3de (patch) | |
tree | 0edd722ce020de9e33fcc107e9adfa02b314344d /src/gen_tiles.c | |
parent | 50122472d9c3150bf8f998df2ee4f5d5fc06f5aa (diff) |
works with images
Diffstat (limited to 'src/gen_tiles.c')
-rw-r--r-- | src/gen_tiles.c | 100 |
1 files changed, 28 insertions, 72 deletions
diff --git a/src/gen_tiles.c b/src/gen_tiles.c index 5462ee3..53e1012 100644 --- a/src/gen_tiles.c +++ b/src/gen_tiles.c @@ -4,88 +4,56 @@ #include <sys/stat.h> #include "typedef.h" #include "ppm.h" +#include "config.h" -#define TILES 3 #define TILE_WIDTH 3 #define TILE_HEIGHT 3 -#define TILE_SZ ((TILE_WIDTH) * (TILE_HEIGHT)) - -FILE *fp; // possible types: X T I -char symetry[TILES] = "XTXIT"; +char symetry[TILES_CAP] = "XTIIT"; -small_t tiles[TILES][TILE_SZ] = { +small_t tiles[TILES_CAP][TILE_WIDTH*TILE_HEIGHT] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { - 0, 1, 0, + 0, 0, 0, 1, 1, 1, - 0, 0, 0 + 0, 1, 0 }, { 0, 1, 0, 1, 1, 1, 0, 1, 0 },{ - 0, 1, 0, - 0, 1, 0, - 0, 1, 0 + 0, 0, 0, + 1, 1, 1, + 0, 0, 0 }, { 0, 1, 0, - 1, 1, 0, + 0, 1, 1, 0, 0, 0 } }; -small_t tiles_connections[TILES][4] = { +small_t tiles_connections[TILES_CAP][4] = { { 0, 0, 0, 0 }, - { 1, 1, 1, 0 }, + { 0, 1, 1, 1 }, { 1, 1, 1, 1 }, - { 1, 0, 0, 1 }, - { 1, 0, 1, 0 }, + { 0, 1, 1, 0 }, + { 1, 1, 0, 0 }, }; -int rotate(int x, int y, int r, int w) -{ - switch(r) { - case 0: // no roatate - return y * w + x; - case 1: // right - return (w*w - w) + y - (x * w); - case 2: // left - return (w-1) - y + (x * w); - case 3: // down - return (w*w-1) - (y * w) - x; - } - - return -1; -} - -void rotate_tiles(small_t *tile, int i, int r) -{ - for(size_t y = 0; y < TILE_HEIGHT; y++) - for(size_t x = 0; x < TILE_WIDTH; x++) - tile[y * TILE_WIDTH + x] = tiles[i][rotate(x, y, r, TILE_WIDTH)]; -} - -void rotate_connections(small_t *tc, int i, int r) -{ - for(int y = 0; y < 2; y++) - for(int x = 0; x < 2; x++) - tc[y * 2 + x] = tiles_connections[i][rotate(x, y, r, 2)]; - -} - void set_color(small_t *pixels, small_t *t, int x, int y, char k, char blank, char connection) { pixels[(y * TILE_WIDTH + x)*3 + k] = (t[y * TILE_WIDTH + x] == 0) ? blank : connection; } +FILE *fp; void save(small_t *t, small_t *n, int i) { +#ifdef GENERATE_PPM_TILES char file_name[64] = {0}; sprintf(file_name, "files/tiles/tile_%d.ppm", i); @@ -101,6 +69,7 @@ void save(small_t *t, small_t *n, int i) save_as_ppm(file_name, pixels, TILE_WIDTH, TILE_HEIGHT, 1); free(pixels); printf("Saved file: %s\n", file_name); +#endif small_t connections = 0; for(int c = 0; c < 4; c++) @@ -118,34 +87,21 @@ void gen_rotations() fp = fopen("files/tiles/tiles.dat", "wb"); - for(int i = 0, n = 0; i < TILES; i++, n++) + size_t tiles_sz = sizeof(tiles_to_load)/sizeof(int); + fwrite(&tiles_sz, sizeof(size_t), sizeof(size_t), fp); + + char syms[TILES_CAP]; + size_t sym_sz = 0; + + for(int n = 0; n < tiles_sz; n++) { - small_t tile[TILE_SZ]; - small_t tile_connections[4]; - switch(symetry[i]) - { - case 'X': - save(tiles[i], tiles_connections[i], n); - break; - case 'T': ; - for(int j = 0; j < 4; j++) { - rotate_tiles(tile, i, j); - rotate_connections(tile_connections, i, j); - - save(tile, tile_connections, n); - n++; - } n--; - break; - case 'I': - save(tiles[i], tiles_connections[i], n); - n++; - rotate_tiles(tile, i, 1); - rotate_connections(tile_connections, i, 1); - save(tile, tile_connections, n); - break; - } + int i = tiles_to_load[n]; + save(tiles[i], tiles_connections[i], n); + syms[sym_sz++] = symetry[i]; } + fwrite(syms, 1, sym_sz, fp); + fclose(fp); } |