add redraw the tree with KEY_R

This commit is contained in:
Nikola Petrov 2024-02-22 13:56:48 +01:00
parent 3d9e6c9f7d
commit 0fd7aeb8d7

View File

@ -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<branch> tree(MAX_DEPTH);
static std::list<draw_args> 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);