export tree functions to a class

This commit is contained in:
Nikola Petrov
2024-03-03 21:06:06 +01:00
parent 7e693bb73f
commit cccafdda37
4 changed files with 173 additions and 135 deletions

12
inc/Math.hpp Normal file
View File

@@ -0,0 +1,12 @@
#include "raylib.h"
#include "raymath.h"
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;
}

43
inc/Tree.hpp Normal file
View File

@@ -0,0 +1,43 @@
#include "raylib.h";
#include <cstdint>
#include <vector>
#include <list>
#define MAX_DEPTH 11
struct branch
{
Color color;
uint8_t numOfBranches;
float lenghthRatio;
};
struct draw_args
{
Vector2 start;
float angleDeg;
float lenghth;
int dep;
};
class Tree
{
public:
Tree(int size);
~Tree();
void Draw(Rectangle dest);
void new_tree();
void generate_tree();
void draw_tree(draw_args first);
void draw_branch(draw_args arg);
Vector2 draw_line(Vector2 start, float angleDeg, float lenghth, int dep);
private:
int size = 0;
RenderTexture2D target = {0};
Vector2 start = {0};
std::vector<branch> tree;
std::list<draw_args> draw_calls;
};