From a286744fe5b62e6fbae4ab53a55bf71a1541be62 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Thu, 22 Feb 2024 14:15:02 +0100 Subject: [PATCH] random num of branches --- main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index e6a04b6..71407be 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,7 @@ Color ColorLerp(Color c1, Color c2, float amount) struct branch { Color color; + uint8_t numOfBranches; }; struct draw_args @@ -68,8 +69,14 @@ void draw_branch(draw_args arg) Vector2 next = draw_line(arg.start, arg.angleDeg, arg.lenghth, arg.dep); float next_len = 0.7f; - draw_calls.push_back((draw_args){next, arg.angleDeg + 45, arg.lenghth * next_len, arg.dep + 1}); - draw_calls.push_back((draw_args){next, arg.angleDeg - 45, arg.lenghth * next_len, arg.dep + 1}); + float sectors = tree[arg.dep].numOfBranches + 1; + float degres = 180.0f / sectors; + + for (size_t i = 0; i < tree[arg.dep].numOfBranches; i++) + { + float newAngle = arg.angleDeg - 90 + (degres * (i + 1)); + draw_calls.push_back((draw_args){next, newAngle, arg.lenghth * next_len, arg.dep + 1}); + } } void draw_tree(draw_args first) @@ -91,6 +98,8 @@ void generate_tree() uint8_t g = GetRandomValue(0, 255); uint8_t b = GetRandomValue(0, 255); tree[i].color = (Color){r, g, b, 255}; + + tree[i].numOfBranches = GetRandomValue(1, 3); } tree[0].color = tree[1].color;