diff --git a/includes/window.hpp b/includes/window.hpp index b59b48d..f5c43b7 100644 --- a/includes/window.hpp +++ b/includes/window.hpp @@ -4,13 +4,13 @@ #define WIDTH 720 #define HEIGHT 420 -int graph(uint32_t *img); -int graph2(uint32_t *img); -int mountain(uint32_t *img); -int cloud(uint32_t *img); -int marble(uint32_t *img); -int random(uint32_t *img); -int wood(uint32_t *img); -int test(uint32_t *img); +int graph(uint32_t *img, int width, int height); +int graph2(uint32_t *img, int width, int height); +int mountain(uint32_t *img, int width, int height); +int cloud(uint32_t *img, int width, int height); +int marble(uint32_t *img, int width, int height); +int random(uint32_t *img, int width, int height); +int wood(uint32_t *img, int width, int height); +int test(uint32_t *img, int width, int height); #endif \ No newline at end of file diff --git a/includes/windowManager/WindowManager.hpp b/includes/windowManager/WindowManager.hpp index 0f51d31..bc8d00c 100644 --- a/includes/windowManager/WindowManager.hpp +++ b/includes/windowManager/WindowManager.hpp @@ -6,24 +6,25 @@ #include #include #include -#include "err.h" + +typedef int (*renderFunction)(u_int32_t *img, int width, int height); class WindowManager { public: - WindowManager(int width, int height, int (*)(u_int32_t *img)); + WindowManager(int width, int height, renderFunction r); ~WindowManager(); u_int32_t *get_image_addr() { return img; } - void load_render(int (*)(u_int32_t *img)); + void load_render(renderFunction r); void loop(); private: - void update_image(int (*)(u_int32_t *img)); + void update_image(renderFunction); void display_image(); void handle_events(XEvent &GeneralEvent); - int (*render)(u_int32_t *img); - std::vector renderFunctions; + renderFunction render; + std::vector renderFunctions; uint8_t ptrTabIndex; u_int32_t *img; int WindowX; diff --git a/srcs/effects/cloud.cpp b/srcs/effects/cloud.cpp index f76924e..acc5530 100644 --- a/srcs/effects/cloud.cpp +++ b/srcs/effects/cloud.cpp @@ -3,16 +3,16 @@ #include "window.hpp" #include "noise/perlin.hpp" -int cloud(uint32_t *img) { +int cloud(uint32_t *img, int width, int height) { static PerlinNoise PerlinNoise; static float time = 0.0; - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { float n = PerlinNoise.noise(x / 100.0 + time, (y / 100.0) + time) * 0.5; n += PerlinNoise.noise(x / 50.0 + time, (y / 50.0) + time) * 0.25; int color = static_cast((n + 1) * 127.5); - img[y * WIDTH + x] = (color << 16) | (color << 8) | color ; + img[y * width + x] = (color << 16) | (color << 8) | color ; } } time += 0.1; diff --git a/srcs/effects/debug.cpp b/srcs/effects/debug.cpp index 685eee2..2762f7f 100644 --- a/srcs/effects/debug.cpp +++ b/srcs/effects/debug.cpp @@ -3,16 +3,15 @@ #include "window.hpp" #include "noise/perlin.hpp" -int test(uint32_t *img) { +int test(uint32_t *img, int width, int height) { static bool a = true; - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { if (a) - img[y * WIDTH + x] = 0x202020; + img[y * width + x] = 0x202020; else - img[y * WIDTH + x] = 0x0; + img[y * width + x] = 0x0; } } - a = !a; return 0; } \ No newline at end of file diff --git a/srcs/effects/graph.cpp b/srcs/effects/graph.cpp index 605f467..32da127 100644 --- a/srcs/effects/graph.cpp +++ b/srcs/effects/graph.cpp @@ -3,38 +3,38 @@ #include "window.hpp" #include "noise/perlin.hpp" -int graph(uint32_t *img) { +int graph(uint32_t *img, int width, int height) { static PerlinNoise PerlinNoise; static float time = 0.0; - for (int x = 0; x < WIDTH; x++) { + for (int x = 0; x < width; x++) { float n = PerlinNoise.noise(x / 100.0 + time, 0.0) * 0.5; - int y = static_cast((n + 1) * (HEIGHT >> 1)); - for (int i = 0; i < HEIGHT; ++i) { + int y = static_cast((n + 1) * ((int)height >> 1)); + for (int i = 0; i < height; ++i) { if (i == y) - img[i * WIDTH + x] = 0xFFFFFF; + img[i * width + x] = 0xFFFFFF; else - img[i * WIDTH + x] = 0; + img[i * width + x] = 0; } } time += 0.001; return 0; } -int graph2(uint32_t *img) { +int graph2(uint32_t *img, int width, int height) { static PerlinNoise PerlinNoise; static float time = 0.0; - for (int x = 0; x < WIDTH; x++) { + for (int x = 0; x < width; x++) { float n = PerlinNoise.noise(x / 100.0, time) * 0.5; - int y = static_cast((n + 1) * (HEIGHT >> 1)); - for (int i = 0; i < HEIGHT; ++i) { + int y = static_cast((n + 1) * (height >> 1)); + for (int i = 0; i < height; ++i) { if (i - y < 40 && i - y > -40){ int co = static_cast(255 * (40 - abs(i - y)) / 40); - img[i * WIDTH + x] = 0 << 16| (co << 8) | co; + img[i * width + x] = 0 << 16| (co << 8) | co; } else - img[i * WIDTH + x] = 0; + img[i * width + x] = 0; } } time += 0.001; diff --git a/srcs/effects/marble.cpp b/srcs/effects/marble.cpp index 5ebe23f..e990d14 100644 --- a/srcs/effects/marble.cpp +++ b/srcs/effects/marble.cpp @@ -3,15 +3,15 @@ #include "window.hpp" #include "noise/perlin.hpp" -int marble(uint32_t *img) { +int marble(uint32_t *img, int width, int height) { static PerlinNoise perlinNoise; static float time = 0.0; - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { float n = perlinNoise.noise(x / 100.0 + time, y / 100.0 + time); float marble = sin((x * 0.05 + n * 10.0)); int color = static_cast((marble + 1) * 127.5); - img[y * WIDTH + x] = (color << 16) | (color << 8) | color; + img[y * width + x] = (color << 16) | (color << 8) | color; } } time += 0.01; diff --git a/srcs/effects/mountain.cpp b/srcs/effects/mountain.cpp index 10fc502..83c611f 100644 --- a/srcs/effects/mountain.cpp +++ b/srcs/effects/mountain.cpp @@ -3,7 +3,7 @@ #include "window.hpp" #include "noise/perlin.hpp" -int mountain(uint32_t *img) { +int mountain(uint32_t *img, int width, int height) { static PerlinNoise P(9); static PerlinNoise P2(1000); static PerlinNoise P3(500); @@ -11,24 +11,24 @@ int mountain(uint32_t *img) { /*basic color sunsine gradient no noise*/ - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { float n = P2.noise(x / 10 + (time * 0.5), y / 100.0 + (time * 0.5)) * 0.5 + 0.5; int color = static_cast(n * 255); - img[y * WIDTH + x] = (0 << 16) | (color << 8) | color; + img[y * width + x] = (0 << 16) | (color << 8) | color; } } /*mountain*/ - for (int x = 0; x < WIDTH; x++) { + for (int x = 0; x < width; x++) { float n = P.noise(x / 100.0 + time, 0) * 0.5; float n2 = P2.noise(x / 1000.0 , 0) + P2.noise(x / 40.0 + (time * 0.5), 0) * 0.5; - int y = static_cast((n + 1) * (HEIGHT >> 1)); - int y2 = static_cast((n2 + 1) * (HEIGHT >> 1) ); - for (int i = y2; i < HEIGHT; ++i) { - img[i * WIDTH + x] = 0xf0f0f0; + int y = static_cast((n + 1) * (height >> 1)); + int y2 = static_cast((n2 + 1) * (height >> 1) ); + for (int i = y2; i < height; ++i) { + img[i * width + x] = 0xf0f0f0; } - for (int i = y; i < HEIGHT; ++i) { - img[i * WIDTH + x] = 0x151515; + for (int i = y; i < height; ++i) { + img[i * width + x] = 0x151515; } } time += 0.03; diff --git a/srcs/effects/random.cpp b/srcs/effects/random.cpp index 5bc2414..d99d22d 100644 --- a/srcs/effects/random.cpp +++ b/srcs/effects/random.cpp @@ -2,15 +2,14 @@ #include "window.hpp" #include "noise/perlin.hpp" -int random(uint32_t *img) { +int random(uint32_t *img, int width, int height) { static PerlinNoise PerlinNoise; static float time = 0.0; - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { float r = (PerlinNoise.noise(x * 0.0001 + time, (y * 00.001) + time)) * 0.5; - int color = static_cast((r + 1) * 127.5); - img[y * WIDTH + x] = (color << 16) >> 1| (color << 8) | 0; + img[y * width + x] = (color << 16) >> 1| (color << 8) | 0; } } time += 0.01; diff --git a/srcs/effects/wood.cpp b/srcs/effects/wood.cpp index 1374113..3158068 100644 --- a/srcs/effects/wood.cpp +++ b/srcs/effects/wood.cpp @@ -3,15 +3,15 @@ #include "window.hpp" #include "noise/perlin.hpp" -int wood(uint32_t *img) { +int wood(uint32_t *img, int width, int height) { static PerlinNoise perlinNoise; static float time = 0.0; - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { float n = perlinNoise.noise(x / 100.0 + time, y / 100.0 + time); float wood = sin((x * 0.1 + n * 5.0)); int color = static_cast((wood + 1) * 127.5); - img[y * WIDTH + x] = (color << 16) | (color << 8) | color; + img[y * width + x] = (color << 16) | (color << 8) | color; } } time += 0.01; diff --git a/srcs/windowManager/WindowManager.cpp b/srcs/windowManager/WindowManager.cpp index 1a319a5..5910ce6 100644 --- a/srcs/windowManager/WindowManager.cpp +++ b/srcs/windowManager/WindowManager.cpp @@ -5,7 +5,7 @@ #include #include -WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img)) : +WindowManager::WindowManager(int width, int height, renderFunction render) : render(render), ptrTabIndex(0), WindowX(0), WindowY(0), @@ -108,11 +108,11 @@ void WindowManager::display_image() { XFlush(MainDisplay); } -void WindowManager::update_image(int (*func)(u_int32_t *img)) { - if (func(this->img)) +void WindowManager::update_image(renderFunction r) { + if (r(img, WindowWidth, WindowHeight) != 0) this->isWindowOpen = false; } -void WindowManager::load_render(int (*func)(u_int32_t *img)) { - this->renderFunctions.push_back(func); +void WindowManager::load_render(renderFunction r) { + this->renderFunctions.push_back(r); } \ No newline at end of file