From 0fd7aeb8d76ccb4dbb87c45ee377ea9c61a54142 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Thu, 22 Feb 2024 13:56:48 +0100 Subject: [PATCH] add redraw the tree with KEY_R --- main.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 3f87c02..e6a04b6 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,12 @@ #include "raymath.h" #define MAX_DEPTH 11 +const int screenWidth = 800; +const int screenHeight = 800; +#define textureWidth screenWidth +#define textureHeight screenHeight + +const Vector2 start = {textureWidth / 2, textureHeight}; Color ColorLerp(Color c1, Color c2, float amount) { @@ -32,6 +38,7 @@ struct draw_args static std::vector tree(MAX_DEPTH); static std::list draw_calls; +static RenderTexture2D target; Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, int dep) { @@ -89,27 +96,25 @@ void generate_tree() tree[0].color = tree[1].color; } -int main(void) +void new_tree() { - const int screenWidth = 800; - const int screenHeight = 800; - - InitWindow(screenWidth, screenHeight, "raylib"); - - SetTargetFPS(60); - - const int textureWidth = screenWidth; - const int textureHeight = screenHeight; - - RenderTexture2D target = LoadRenderTexture(textureWidth, textureHeight); - Vector2 start = {textureWidth / 2, textureHeight}; - generate_tree(); BeginTextureMode(target); ClearBackground(WHITE); draw_tree((draw_args){start, 0, textureHeight / 4, 1}); EndTextureMode(); +} + +int main(void) +{ + InitWindow(screenWidth, screenHeight, "raylib"); + + SetTargetFPS(60); + + target = LoadRenderTexture(textureWidth, textureHeight); + + new_tree(); Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height}; Rectangle dest = {0, 0, screenWidth, screenHeight}; @@ -118,6 +123,12 @@ int main(void) while (!WindowShouldClose()) { + + if (IsKeyPressed(KEY_R)) + { + new_tree(); + } + BeginDrawing(); DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);