summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/main.c b/main.c
index 4ae63d9..7a1fda2 100644
--- a/main.c
+++ b/main.c
@@ -16,6 +16,8 @@
#include <raylib.h>
#include <raymath.h>
+#include <stb/stb_image_write.h>
+
#define WIDTH 1024
#define HEIGHT 1024
#define MAX_THREADS 4
@@ -90,6 +92,25 @@ void threads_cancel_render(void)
pthread_join(threads[i], NULL);
}
+bool write_to_png(const char *filepath)
+{
+ unsigned char *image_data = calloc(3 * WIDTH * HEIGHT, sizeof(*image_data));
+
+ size_t image_ptr = 0;
+
+ for (size_t i = 0; i < HEIGHT; ++i)
+ for (size_t j = 0; j < WIDTH; ++j, image_ptr += 3)
+ {
+ Color c = cells[(j * WIDTH) + i];
+ unsigned char colour[3] = {c.r, c.g, c.b};
+ memcpy(image_data + image_ptr, colour, sizeof(*colour) * 3);
+ }
+
+ stbi_write_png(filepath, WIDTH, HEIGHT, 3, image_data, 3 * WIDTH);
+ free(image_data);
+ return true;
+}
+
#define ZOOM_INC 0.3f
#define MOVE_INC WIDTH / 50
int main(void)