diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 67 |
1 files changed, 31 insertions, 36 deletions
@@ -1,28 +1,29 @@ #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> #include <time.h> #include "tiles.h" #include "ppm.h" -#define TILES 5 +#define TILES 6 int *(tiles[TILES]) = {0}; size_t TILE_WIDTH; size_t TILE_HEIGHT; int tile_masks[TILES][4] = { - { 0b00011, 0b00101, 0b01001, 0b10001 }, + { 0b000011, 0b000101, 0b001001, 0b010001 }, - { 0b11100, 0b11010, 0b10110, 0b10001 }, - { 0b11100, 0b11010, 0b01001, 0b01110 }, - { 0b11100, 0b00101, 0b10110, 0b01110 }, - { 0b00011, 0b11010, 0b10110, 0b01110 } + { 0b111100, 0b111010, 0b110110, 0b010001 }, + { 0b111100, 0b111010, 0b001001, 0b101110 }, + { 0b111100, 0b000101, 0b110110, 0b101110 }, + { 0b000011, 0b111010, 0b110110, 0b101110 }, + + { 0b111100, 0b111010, 0b110110, 0b101110 } }; -#define WIDTH_SCALER 3 -#define HEIGHT_SCALER 3 +#define WIDTH_SCALER 10 +#define HEIGHT_SCALER 10 int tiles_board[WIDTH_SCALER * HEIGHT_SCALER] = {0}; @@ -80,15 +81,15 @@ int get_least_entropy_index() void set_index(int i) { - if(count_1s(tiles_board[i]) == 1) { - tiles_board[i] |= 1 << TILES; - goto modify_neighbors; + int n; + + if(count_1s(tiles_board[i]) == 0) { + fprintf(stderr, "ERROR: No possible tiles for this position: %d\n", i); + exit(EXIT_FAILURE); } - // bad way - int n; - while(((tiles_board[i] >> TILES) & 1) != 1) - { + // this bad + do { n = rand() % TILES; if(((tiles_board[i] >> n) & 1) != 1) continue; @@ -96,9 +97,7 @@ void set_index(int i) tiles_board[i] = 0; tiles_board[i] |= 1 << n; tiles_board[i] |= 1 << TILES; - } - -modify_neighbors: + } while(((tiles_board[i] >> TILES) & 1) != 1); if(i / WIDTH_SCALER != 0) // up if(count_1s(tiles_board[i-WIDTH_SCALER]) != (TILES + 1)) @@ -115,19 +114,15 @@ modify_neighbors: if(i / WIDTH_SCALER != (HEIGHT_SCALER - 1)) // down if(count_1s(tiles_board[i+WIDTH_SCALER]) != (TILES + 1)) tiles_board[i+WIDTH_SCALER] &= tile_masks[n][3]; - } int main(void) { time_t seed = time(0); - srand(420); + srand(seed); printf("seed %ld\n", seed); init_tiles_board(); - load_tiles(TILES); - - print_tiles(TILES); while(1) { int lei; @@ -137,23 +132,18 @@ int main(void) break; // every index is set else set_index(lei); - - // for(int i = 0; i < HEIGHT_SCALER; i++) { - // for(int j = 0; j < WIDTH_SCALER; j++) - // printf("%6b ", tiles_board[i * WIDTH_SCALER + j]); - // putchar('\n'); - // } - // putchar('\n'); } + load_tiles(TILES); + int img_wdt = TILE_WIDTH * WIDTH_SCALER; int img_hgt = TILE_HEIGHT * HEIGHT_SCALER; int *image = malloc(img_wdt * img_hgt * sizeof(int)); memset(image, 0, img_wdt * img_hgt * sizeof(int)); - for(int i = 0; i < HEIGHT_SCALER; i++) + for(size_t i = 0; i < HEIGHT_SCALER; i++) { - for(int j = 0; j < WIDTH_SCALER; j++) + for(size_t j = 0; j < WIDTH_SCALER; j++) { int t; for(t = 0; t < TILES; t++) @@ -167,9 +157,14 @@ int main(void) } } - save_as_ppm("file.ppm", image, img_wdt, img_hgt); - free(image); - free_tiles(TILES); + + char file_name[64] = {0}; + sprintf(file_name, "files/file_%ld.ppm", seed); + printf("Saved file with name: %s\n", file_name); + + save_as_ppm(file_name, image, img_wdt, img_hgt, 10); + + free(image); return 0; } |