aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gen_tiles.c50
-rw-r--r--src/main.c10
-rw-r--r--src/ppm.c19
-rw-r--r--src/tiles.c6
-rw-r--r--src/tiles.h2
-rw-r--r--src/typedef.h2
6 files changed, 49 insertions, 40 deletions
diff --git a/src/gen_tiles.c b/src/gen_tiles.c
index e70990e..072ac1e 100644
--- a/src/gen_tiles.c
+++ b/src/gen_tiles.c
@@ -13,22 +13,22 @@
FILE *fp;
// possible types: X T I
-char symetry[TILES] = "XTXIT";
+char symetry[TILES] = "IT";
small_t tiles[TILES][TILE_SZ] = {
{
- 0, 0, 0,
- 0, 0, 0,
- 0, 0, 0
- }, {
- 0, 1, 0,
- 1, 1, 1,
- 0, 0, 0
- }, {
- 0, 1, 0,
- 1, 1, 1,
- 0, 1, 0
- },{
+ // 0, 0, 0,
+ // 0, 0, 0,
+ // 0, 0, 0
+ // }, {
+ // 0, 1, 0,
+ // 1, 1, 1,
+ // 0, 0, 0
+ // }, {
+ // 0, 1, 0,
+ // 1, 1, 1,
+ // 0, 1, 0
+ // },{
0, 1, 0,
0, 1, 0,
0, 1, 0
@@ -40,9 +40,9 @@ small_t tiles[TILES][TILE_SZ] = {
};
small_t tiles_connections[TILES][4] = {
- { 0, 0, 0, 0 },
- { 1, 1, 1, 0 },
- { 1, 1, 1, 1 },
+ // { 0, 0, 0, 0 },
+ // { 1, 1, 1, 0 },
+ // { 1, 1, 1, 1 },
{ 1, 0, 0, 1 },
{ 1, 0, 1, 0 },
};
@@ -78,12 +78,28 @@ void rotate_connections(small_t *tc, int i, int r)
}
+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;
+
+}
+
void save(small_t *t, small_t *n, int i)
{
char file_name[64] = {0};
sprintf(file_name, "files/tiles/tile_%d.ppm", i);
- save_as_ppm(file_name, t, TILE_WIDTH, TILE_HEIGHT, 1);
+
+ small_t *pixels = malloc(TILE_WIDTH * TILE_HEIGHT *3);
+ for(int y = 0; y < TILE_HEIGHT; y++)
+ for(int x = 0; x < TILE_WIDTH; x++) {
+ set_color(pixels, t, x, y, 0, 255, 0);
+ set_color(pixels, t, x, y, 1, 255, 0);
+ set_color(pixels, t, x, y, 2, 255, 255);
+ }
+
+ save_as_ppm(file_name, pixels, TILE_WIDTH, TILE_HEIGHT, 1);
+ free(pixels);
printf("Saved file: %s\n", file_name);
small_t connections = 0;
diff --git a/src/main.c b/src/main.c
index 353efe1..8461707 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,8 +12,8 @@ size_t TILES;
size_t TILE_WIDTH;
size_t TILE_HEIGHT;
-size_t SWIDTH = 10;
-size_t SHEIGHT = 10;
+size_t SWIDTH = 30;
+size_t SHEIGHT = 30;
int get_least_entropy_index()
{
@@ -112,7 +112,7 @@ int main(void)
size_t img_wdt = TILE_WIDTH * SWIDTH;
size_t img_hgt = TILE_HEIGHT * SHEIGHT;
- small_t *image = malloc(img_wdt * img_hgt * sizeof(small_t));
+ small_t *image = malloc(img_wdt * img_hgt * 3);
memset(image, 0, img_wdt * img_hgt);
for(size_t i = 0; i < SHEIGHT; i++)
@@ -124,7 +124,9 @@ int main(void)
for(size_t y = 0; y < TILE_HEIGHT; y++)
for(size_t x = 0; x < TILE_WIDTH; x++)
- image[(y+(i*TILE_HEIGHT)) * img_wdt + (x+(j*TILE_WIDTH))] = get_tile_pixel(t, x, y);
+ for(int k = 0; k < 3; k++)
+ image[((y+(i*TILE_HEIGHT))*img_wdt+(x+(j*TILE_WIDTH)))*3 + k] =
+ get_tile_pixel(t, x, y, k);
}
}
diff --git a/src/ppm.c b/src/ppm.c
index 24216f5..7bc8bb7 100644
--- a/src/ppm.c
+++ b/src/ppm.c
@@ -21,12 +21,10 @@ void save_as_ppm(char* file_path, small_t *t, size_t width, size_t height, size_
for(size_t i = 0; i < height * scaler; i++)
for(size_t j = 0; j < width * scaler; j++)
- {
- char c = (t[(i/scaler) * width + (j/scaler)] == 0) ? 255 : 0;
- for(int j = 0; j < 3; j++)
+ for(int k = 0; k < 3; k++) {
+ char c = t[((i/scaler) * width + (j/scaler))*3 + k];
fwrite(&c, 1, 1, fp);
- }
-
+ }
fclose(fp);
}
@@ -52,16 +50,9 @@ small_t *load_from_ppm(char *file_path, size_t *width, size_t *height)
*height = atoi(strtok(NULL, " "));
(void)strtok(NULL, " ");
- char *pixels = malloc((*width) * (*height ) * 3);
-
- fread(pixels, *width*3, *height, fp);
-
- small_t *t = malloc((*width) * (*height) * sizeof(small_t));
- for(size_t i = 0; i < *height; i++)
- for(size_t j = 0; j < *width; j++)
- t[i * *width + j] = (pixels[(i * *width + j) * 3] == 0) ? 1 : 0;
+ small_t *t = malloc((*width) * (*height ) * 3);
- free(pixels);
+ fread(t, *width*3, *height, fp);
fclose(fp);
diff --git a/src/tiles.c b/src/tiles.c
index 6b7a39b..d3fdc9d 100644
--- a/src/tiles.c
+++ b/src/tiles.c
@@ -39,16 +39,16 @@ void print_tiles()
for(size_t y = 0; y < TILE_HEIGHT; y++)
{
for(size_t x = 0; x < TILE_WIDTH; x++)
- putchar(tiles[i][y * TILE_WIDTH + x] + '0');
+ putchar((tiles[i][(y * TILE_WIDTH + x)*3 + 0]) == 0 ? '#' : '.');
putchar('\n');
}
putchar('\n');
}
}
-int get_tile_pixel(size_t t, size_t x, size_t y)
+int get_tile_pixel(size_t t, size_t x, size_t y, int k)
{
- return tiles[t][y * TILE_WIDTH + x];
+ return tiles[t][(y * TILE_WIDTH + x)*3 + k];
}
small_t *load_tile_connections()
diff --git a/src/tiles.h b/src/tiles.h
index cdf27e1..49026dc 100644
--- a/src/tiles.h
+++ b/src/tiles.h
@@ -4,7 +4,7 @@
void load_tiles();
void free_tiles();
void print_tiles();
-int get_tile_pixel(size_t t, size_t x, size_t y);
+int get_tile_pixel(size_t t, size_t x, size_t y, int k);
small_t *load_tile_connections();
void calc_tiles();
diff --git a/src/typedef.h b/src/typedef.h
index 7bde436..2e7c672 100644
--- a/src/typedef.h
+++ b/src/typedef.h
@@ -6,7 +6,7 @@
#include <stdint.h>
#include <stddef.h>
-typedef uint8_t small_t;
+typedef unsigned char small_t;
typedef size_t big_t;
#endif