diff --git a/main.cpp b/main.cpp index a8d20dd..ff44156 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,18 @@ #define MAX_DEPTH 11 +Color ColorLerp(Color c1, Color c2, float amount) +{ + Color ret{0}; + + ret.r = Clamp(Lerp(c1.r, c2.r, amount), 0, 255); + ret.g = Clamp(Lerp(c1.g, c2.g, amount), 0, 255); + ret.b = Clamp(Lerp(c1.b, c2.b, amount), 0, 255); + ret.a = Clamp(Lerp(c1.a, c2.a, amount), 0, 255); + + return ret; +} + struct branch { Color color; @@ -13,14 +25,23 @@ struct branch static std::vector tree(MAX_DEPTH); -Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, Color color) +Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, int dep) { angleDeg += 180.0f; float angle = (angleDeg * PI) / 180.0f; float nx = lenghth * std::sin(angle); float ny = lenghth * std::cos(angle); Vector2 end = {start.x + nx, start.y + ny}; - DrawLineEx(start, end, 2.0f, color); + + float thick = 2.0; + float fstep = 1.0 / ((lenghth / thick) * 1.5); + + for (float i = 0; i < 1; i += fstep) + { + Vector2 point = Vector2Lerp(start, end, i); + Color color = ColorLerp(tree[dep - 1].color, tree[dep].color, i); + DrawCircleV(point, thick, color); + } return end; } @@ -29,7 +50,7 @@ void draw_branch(Vector2 start, float angle, float len, int dep) if (dep >= MAX_DEPTH) return; - Vector2 next = draw_line(start, angle, len, tree[dep].color); + Vector2 next = draw_line(start, angle, len, dep); float next_len = 0.7f; draw_branch(next, angle + 45, len * next_len, dep + 1); @@ -45,6 +66,8 @@ void generate_tree() uint8_t b = GetRandomValue(0, 255); tree[i].color = (Color){r, g, b, 255}; } + + tree[0].color = tree[1].color; } int main(void)