
Canvas contains the RenderTexture2D contains the Tree and now it's eazy to add more modules
42 lines
573 B
C++
42 lines
573 B
C++
#include <cstdint>
|
|
#include <vector>
|
|
#include <list>
|
|
#include "raylib.h"
|
|
|
|
#define MAX_DEPTH 11
|
|
|
|
struct Branch
|
|
{
|
|
Color color;
|
|
uint8_t numOfBranches;
|
|
float lenghthRatio;
|
|
};
|
|
|
|
struct DrawArgs
|
|
{
|
|
Vector2 start;
|
|
float angleDeg;
|
|
float lenghth;
|
|
int dep;
|
|
};
|
|
|
|
class Tree
|
|
{
|
|
|
|
public:
|
|
Tree() = default;
|
|
~Tree() = default;
|
|
void init(int size);
|
|
void newGen();
|
|
|
|
private:
|
|
int size = 0;
|
|
Vector2 start = {0};
|
|
std::vector<Branch> branches;
|
|
std::list<DrawArgs> draw_calls;
|
|
|
|
void generateBranches();
|
|
void drawTree();
|
|
void drawBranch();
|
|
Vector2 drawLine();
|
|
}; |