diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-09-03 20:00:10 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-09-03 20:00:10 +0100 |
commit | c8ecce95378407e8202c2d9d0b405a3ff37f9c96 (patch) | |
tree | e1520e3e13ce0bf8827336817f3baa875ade70a1 | |
parent | ab7db03aaa0490e0fac7a00add0b85b304553c78 (diff) | |
download | oreobrot-master.tar.gz oreobrot-master.tar.bz2 oreobrot-master.zip |
Found and fixed a bug I would've never noticed in abelian sandpile:
the png is technically rotated by 90 using the standard WIDTH then
HEIGHT for loop, so I had to switch them. As the abelian sandpile
fractal is 4 way symmetric this wasn't noticeable.
-rw-r--r-- | main.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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) |